You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Mohana Ramaratnam <mo...@npg.wustl.edu> on 2006/07/18 21:58:36 UTC

XMLBeans DOM Document

I am trying to get a DOM document to be then used with Xalan's XPathAPI.
This is the code that I have:

 

        String xmlFile = "dom.xml"; 

            XmlObject xmlObject = new XmlReader().read(xmlFile);

            DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();

            // MUST be TRUE or can't get back to bean land

            factory.setNamespaceAware(true);

            DocumentBuilder builder = factory.newDocumentBuilder();

            // Switch to org.w3c.dom.Document - xmlbeans.getDomNode()
doesn't

            // really seem to give you this

            ByteArrayOutputStream out = new ByteArrayOutputStream();

            xo.save(out,new XmlOptions().setSavePrettyPrint());

            Document doc = builder.parse(new InputSource(new
ByteArrayInputStream(out.toByteArray())));

NodeList nodes = XPathAPI.selectNodeList(doc,"/Pipeline");

           System.out.println("Number of nodes is " +
nodes.getLength());

           DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();

           DocumentBuilder builder = dbf.newDocumentBuilder();

           Document doc1 = builder.parse( new File(xmlFile));

           NodeList nodes1 = XPathAPI.selectNodeList(doc1,"/Pipeline");

           System.out.println("Number of nodes is " +
nodes1.getLength());

 

I get two different answers in the system out. Any ideas as to what
could be wrong in creating a DOM document from a XMLBeans object?


RE: XMLBeans DOM Document

Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
Mohana,
 
I would look in the "out" byte array and see what it looks like. By
doing xo.save(...) (by the way, who is "xo"?) you completely bypass
XmlBeans, so it's a matter of what document are you really loading.
 
It would be more interesting, from an XmlBeans perspective, to know what
results you get from XmlObject.getDomNode() and XmlObject.newDomNode()
 
Radu

________________________________

From: Mohana Ramaratnam [mailto:mohanar@npg.wustl.edu] 
Sent: Tuesday, July 18, 2006 12:59 PM
To: user@xmlbeans.apache.org
Subject: XMLBeans DOM Document



I am trying to get a DOM document to be then used with Xalan's XPathAPI.
This is the code that I have:

 

        String xmlFile = "dom.xml"; 

            XmlObject xmlObject = new XmlReader().read(xmlFile);

            DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();

            // MUST be TRUE or can't get back to bean land

            factory.setNamespaceAware(true);

            DocumentBuilder builder = factory.newDocumentBuilder();

            // Switch to org.w3c.dom.Document - xmlbeans.getDomNode()
doesn't

            // really seem to give you this

            ByteArrayOutputStream out = new ByteArrayOutputStream();

            xo.save(out,new XmlOptions().setSavePrettyPrint());

            Document doc = builder.parse(new InputSource(new
ByteArrayInputStream(out.toByteArray())));

NodeList nodes = XPathAPI.selectNodeList(doc,"/Pipeline");

           System.out.println("Number of nodes is " +
nodes.getLength());

           DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();

           DocumentBuilder builder = dbf.newDocumentBuilder();

           Document doc1 = builder.parse( new File(xmlFile));

           NodeList nodes1 = XPathAPI.selectNodeList(doc1,"/Pipeline");

           System.out.println("Number of nodes is " +
nodes1.getLength());

 

I get two different answers in the system out. Any ideas as to what
could be wrong in creating a DOM document from a XMLBeans object?

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.