Java 怎么实现AltoVAXML用法示例

2019年7月29日20:46:44Java 怎么实现AltoVAXML用法示例已关闭评论 348 1104字阅读3分40秒

1.简介

Java 怎么实现AltoVAXML用法示例?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
import com.altova.engines.*;
import java.io.*;


public class AltovaXMLJavaExample

{
    public static void main(String[] args) {
        String inFilename = "c:/program files/altova/altovaxml2007/AltovaXMLexamples/simple.xml";
        String doesNotExist = "c:/program files/doesNotExist.xml";

        String xqFilename = "c:/program files/altova/altovaxml2007/AltovaXMLexamples/CopyInput.xq";
        String resultString;
        System.out.println("AltovaXML Java JNI XQuery");

        
        try {
            IAltovaXMLFactory objXmlApp = AltovaXMLFactory.getInstance();
            
            IXMLValidator val = objXmlApp.getXMLValidatorInstance();
            IXQuery xq = objXmlApp.getXQueryInstance();
            
            
            val.setInputXMLFileName(inFilename);
            if (val.isWellFormed()) { 
                xq.setInputXMLFileName(inFilename);
                xq.setXQueryFileName(xqFilename);
                
                resultString = xq.executeAndGetResultAsString();
                if (resultString == null) {
                    System.out.println("XQuery error : "
                            + xq.getLastErrorMessage());
                } else {
                    System.out.println("Transform contents>>"
                            + resultString);
                }
            } else {
                System.out.println("Not wellformed error>>"
                        + val.getLastErrorMessage());
            }
            
            objXmlApp.releaseInstance();
        } catch (Exception e) {
            System.out.println("Error : " + e);
        }
    }
}

 
继续阅读
编程十万个怎么办