• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML parsing

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Instead of



You can use parse(File f) method...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic