Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

XML parsing - #text

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
    Bookmark Topic Watch Topic
  • New Topic