aspose file tools*
The moose likes Java in General and the fly likes XML parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "XML parsing" Watch "XML parsing" New topic
Author

XML parsing

Omar Mohaidat
Ranch Hand

Joined: Jan 16, 2008
Posts: 34
Hi all,

I am trying to pars XML file using this import org.w3c.dom.* by this code


but the problem, the value of document variable is null, i don't know why.
my XML file :


any help?

Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Give the absolute full path of the xml file...


SCJP 6 [SCJP - Old is Gold]
Omar Mohaidat
Ranch Hand

Joined: Jan 16, 2008
Posts: 34
Hi Ram,

I set the absolute full path but I got same issue, i think if the problem in the path the exception should be file not found exception.

thanks for your response.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
the value of document variable is null,


A familiar problem. Consult the table in the org.w3c.dom.Node JavaDocs.

You will see that Document type nodes return null for nodeValue (as for example in a System.out.println statement)

Everybody working with XML DOM methods should become very very familiar with that table.

Bill
Omar Mohaidat
Ranch Hand

Joined: Jan 16, 2008
Posts: 34

A familiar problem. Consult the table in the org.w3c.dom.Node JavaDocs.

You will see that Document type nodes return null for nodeValue (as for example in a System.out.println statement)

Everybody working with XML DOM methods should become very very familiar with that table.

Bill

Thank you for your great comment.

yes, as you said the node name is found and node value is null of document, but is this mean we can't work on document? regarding to XML file, I used this code to get the elements:


nodeList equal null, is this the correct way to get elements?
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Since the tags in your xml does not have "id" attribute, getElementById() is not valid... at the same time, it will return an element with the specified "id"... If in need of "stmt" elements list, getElementsByTagName(String tagname) of "Document" class can be used...
Omar Mohaidat
Ranch Hand

Joined: Jan 16, 2008
Posts: 34
yes, I have to use getElementsByTagName(String tagname) method, it is working fine now.

thank you very much
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247


Instead of



You can use parse(File f) method...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML parsing