• 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 - #text

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

cd_catalog.xml



Testxml.java



Output :



The question is why there is #text after each item ??? do i have to do something like x = x + 2 & j = j + 2 ???
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

j should start from 1 and has to be incremented as j+=2 after every iteration. This is because when you get the child nodes of each CD node, there are 13 childnodes. They are CD , Title , Text in Title and so on for other elements in CD.

 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but when passe xml using java script it does not display #text why so ??? I do not need increment by 2 in case of java script.

Is there any specific reason ???
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you say getChildNodes it gets the text nodes or the text content as one of the child nodes. Thats why you get 6 extra childnodes when you say getLength() i.e. it shows 13 instead of 6.
 
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
Take a look at the JavaDocs for org.w3c.dom.Node - the base class for all DOM components. There is a lovely table there that everybody should get familiar with showing what values each type of Node has for "nodeName" and "nodeValue"

A Node of Text type has the name "#text"

So - your code that has the println.... getNodeName() is doing what is expected.

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic