Java 怎么使用Altova XML

2019年7月29日20:46:19Java 怎么使用Altova XML已关闭评论 559 1188字阅读3分57秒

1.简介

Java 怎么使用Altova XML?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
import com.altova.automation.AltovaXML.*;
import com.altova.automation.libs.AutomationException;

public class UseAltovaXML {

    
    public static void main(String[] args) {
        
        
        
        String strExamplesFolder = System.getenv("ProgramFiles")
                + "/Altova/AltovaXML2012/AltovaXMLExamples/";

        String inFilename = strExamplesFolder + "simple.xml";
        String xqFilename = strExamplesFolder + "CopyInput.xq";
        System.out.println("AltovaXML Java JNI XQuery");

        AltovaXMLFactory xmlFactory = null;
        try {
            
            xmlFactory = new AltovaXMLFactory();

            
            XMLValidator validator = xmlFactory.getXMLValidator();
            XQuery xQuery = xmlFactory.getXQuery();

            
            validator.setInputXMLFileName(inFilename);
            if (validator.isWellFormed()) {
                
                xQuery.setInputXMLFileName(inFilename);
                xQuery.setXQueryFileName(xqFilename);

                
                String resultString = xQuery.executeAndGetResultAsString();
                if (resultString == null)
                    System.out.println("XQuery error: "
                            + xQuery.getLastErrorMessage());
                else
                    System.out.println("Transform contents: "
                            + resultString);
            } else
                System.out.println("Not wellformed error: "
                        + validator.getLastErrorMessage());

        } catch (AutomationException e) {
            
            System.out.println("Error accessing AltovaXML: "
                    + e.getMessage());
        } finally {
            
            if (xmlFactory != null)
                xmlFactory.dispose();
        }
    }
}

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