• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML parsing

 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give the absolute full path of the xml file...
 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I have to use getElementsByTagName(String tagname) method, it is working fine now.

thank you very much
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Instead of



You can use parse(File f) method...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic