Project

Profile

Help

Bug #4509 ยป TEST.java

Gerben Abbink, 2020-04-01 16:52

 
import java.io.*;
import javax.xml.transform.sax.*;
import net.sf.saxon.dom.*;
import net.sf.saxon.s9api.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class TEST{

public static void main(String[] args){
try{
Processor processor = new Processor(false);
DocumentBuilder documentBuilder = processor.newDocumentBuilder();
SAXSource saxSource = new SAXSource(new InputSource(new StringReader("<root xmlns='namespace' abc='100'><element0 def='200'/><element1 ghi='300'/></root>")));
XdmNode node = documentBuilder.build(saxSource);
Document document = (DocumentOverNodeInfo)DocumentOverNodeInfo.wrap(node.getUnderlyingNode());
Element root = document.getDocumentElement();
Element element0 = (Element)root.getChildNodes().item(0);
System.out.println(String.format("%s", element0.getNodeName()));
for(int i = 0; i < element0.getAttributes().getLength(); i++){
System.out.println(String.format("element0 attribute[%d] %s=%s", i, element0.getAttributes().item(i).getNodeName(), element0.getAttributes().item(i).getNodeValue()));
}
System.out.println("");

Element element1 = (Element)root.getChildNodes().item(1);
System.out.println(String.format("%s", element1.getNodeName()));
for(int i = 0; i < element1.getAttributes().getLength(); i++){
System.out.println(String.format("element1 attribute[%d] %s=%s", i, element1.getAttributes().item(i).getNodeName(), element1.getAttributes().item(i).getNodeValue()));
}
System.out.println("");

System.out.println(String.format("treeModel=%s", documentBuilder.getTreeModel().getClass().getName()));

System.out.println("java -cp 'SaxonHE9-9-17J\\saxon9he.jar';. TEST");
System.out.println("ACTUAL OUTPUT ON MY PC");
System.out.println("element0");
System.out.println("element0 attribute[0] xmlns:xml=http://www.w3.org/XML/1998/namespace");
System.out.println("element0 attribute[1] def=200");
System.out.println("element1");
System.out.println("element1 attribute[0] xmlns:xml=http://www.w3.org/XML/1998/namespace");
System.out.println("element1 attribute[1] ghi=300");
System.out.println("treeModel=net.sf.saxon.om.TreeModel$TinyTree");
System.out.println("");
System.out.println("java -cp 'SaxonHE10-0J\\saxon-he-10.0.jar';. TEST");
System.out.println("ACTUAL OUTPUT ON MY PC");
System.out.println("element0");
System.out.println("element0 attribute[0] xmlns=namespace");
System.out.println("element0 attribute[1] def=200");
System.out.println("element1");
System.out.println("element1 attribute[0] xmlns=namespace");
System.out.println("element1 attribute[1] ghi=300");
System.out.println("treeModel=net.sf.saxon.om.TreeModel$TinyTree");
System.out.println("");
}
catch(Exception e){
}
}
}
    (1-1/1)