Project

Profile

Help

Bug #4509 ยป TEST.java

Gerben Abbink, 2020-04-01 16:52

 
1
import java.io.*;
2
import javax.xml.transform.sax.*;
3
import net.sf.saxon.dom.*;
4
import net.sf.saxon.s9api.*;
5
import org.w3c.dom.*;
6
import org.xml.sax.*;
7

    
8
public class TEST{
9

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

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

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

    
34
                        System.out.println("java -cp 'SaxonHE9-9-17J\\saxon9he.jar';. TEST");
35
                        System.out.println("ACTUAL OUTPUT ON MY PC");
36
                        System.out.println("element0");
37
                        System.out.println("element0 attribute[0] xmlns:xml=http://www.w3.org/XML/1998/namespace");
38
                        System.out.println("element0 attribute[1] def=200");
39
                        System.out.println("element1");
40
                        System.out.println("element1 attribute[0] xmlns:xml=http://www.w3.org/XML/1998/namespace");
41
                        System.out.println("element1 attribute[1] ghi=300");
42
                        System.out.println("treeModel=net.sf.saxon.om.TreeModel$TinyTree");
43
                        System.out.println("");
44
                        
45
                        System.out.println("java -cp 'SaxonHE10-0J\\saxon-he-10.0.jar';. TEST");
46
                        System.out.println("ACTUAL OUTPUT ON MY PC");
47
                        System.out.println("element0");
48
                        System.out.println("element0 attribute[0] xmlns=namespace");
49
                        System.out.println("element0 attribute[1] def=200");
50
                        System.out.println("element1");
51
                        System.out.println("element1 attribute[0] xmlns=namespace");
52
                        System.out.println("element1 attribute[1] ghi=300");
53
                        System.out.println("treeModel=net.sf.saxon.om.TreeModel$TinyTree");
54
                        System.out.println("");
55
                }
56
                catch(Exception e){
57
                }
58
        }
59
}
    (1-1/1)