dcsimg
Is there a difference between building a document using a DocumentBuilder and a DOMParser?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, June 5, 2003 07:49 AM

Hello, Is there a difference between building a document using a DocumentBuilder and a DOMParser? I try to use XPath expressions with both, but only when I use the DocumentBuilder to create my Document, I receive results. A Document build with a DOMParser does not give any results when trying to extract information with XPath expressions. Thus, is there a difference between these to snippets of parse-code with regard to XPath: // Code 1: File file = new File("test.xml"); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dfactory.newDocumentBuilder(); Document doc = builder.parse(file);    More>>


Hello,



Is there a difference between building a document using a DocumentBuilder and a DOMParser? I try to use XPath expressions with both, but only when I use the DocumentBuilder to create my Document, I receive results. A Document build with a DOMParser does not give any results when trying to extract information with XPath expressions.



Thus, is there a difference between these to snippets of parse-code with regard to XPath:


			
// Code 1:
File file = new File("test.xml");
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dfactory.newDocumentBuilder();
Document doc = builder.parse(file);

// Code 2:
File file = new File("test.xml");
InputSource inputSource = new InputSource(new FileInputStream(file));
DOMParser parser = new DOMParser();
parser.parse(inputSource);
Document doc = parser.getDocument();


Thank you,


Joeri Theelen

   <<Less

Re: Is there a difference between building a document using a DocumentBuilder and a DOMParser?

Posted By:   Joeri_Theelen  
Posted On:   Friday, June 6, 2003 05:42 AM

Ok,


Let me answer my own question. A DOMParser-object can have several features and/or properties set. One of them is important for XPath-expressions:



parser.setFeature("http://xml.org/sax/features/namespaces", false);


The document given by this parser acts the same as the document given by the DocumentBuilder.


Chears,


Joeri

About | Sitemap | Contact