Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i get [#document: null] when parsing xml file

Status
Not open for further replies.

aditi1

IS-IT--Management
Aug 6, 2003
1
IL
hi!
this code:

// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validating);

// Create the builder and set error handler class
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new BasicErrHandler());

// Create the doc by parsing the file
Document doc = builder.parse(new File(filename));

returns a document that has a strange value of "[#document: null]"
the xml file is very simple and i know the builder finds it.
what is wrong ??

thanks

adi
 
Hi! Your document is parsed successfully. But to manipulate the doc object following is the code:

Document xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("c:/sample.xml");
Element rootElement = xmlDoc.getDocumentElement();

Now you can manipulate rootElement according to the DTD/Schema you've assigned with the file. e.g.

System.out.println(rootElement.getChildElements().getLength());
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top