O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing an XML Document to Display Node Type and Content

In the previous example, the code listed the names of each node in the ch07_01.xml document. However, you can do more than that: You can also use the nodeValue property to list the value of each node, and I'll do that in this section. In addition, you can indicate the type of each node you come across by checking the nodeType property. Here are the possible values for this property:

  • 1: Element

  • 2: Attribute

  • 3: Text

  • 4: CDATA section

  • 5: Entity reference

  • 6: Entity

  • 7: Processing instruction

  • 8: Comment

  • 9: Document

  • 10: Document type

  • 11: Document fragment

  • 12: Notation

Here's how I determine the type of a particular node, using a JavaScript switch statement of the kind we saw in the previous chapter:

 function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required