Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use XML DOM API to go to every non-text nodes?

Tags:

dom

xml

I am new to XML, and DOM. I guess I need to use DOM API to find go through every non-text nodes once, and output the node name.

say I got this example XML from W3C

<bookstore>

<book category="cooking">
 <title lang="en">Everyday Italian</title>
 <author>Giada De Laurentiis</author>
 <year>2005</year>
 <price>30.00</price>
 <page pagenumber="550"/>
</book>

<book category="children">
 <title lang="en">Harry Potter</title>
 <author>J K. Rowling</author>
 <year>2005</year>
 <price>29.99</price>
 <page pagenumber="500"/>
</book>
</bookstore>

I need to find node such as <page pagenumber="500" /> which is a non-text node

How can I do that? seduo-code would be fine too. Thanks

can I say

 while (x.nodeValue == NULL) {
   read the next node ?
}

I guess I should make myself clear, no assumption on any docuemnts. This should work on all XML as long as there is a non-text node. I guess this should be done in the order from top-down and from left to right for every nodes. :(

like image 776
Jonathan Avatar asked Nov 20 '25 00:11

Jonathan


1 Answers

XPATH ="//*[not(text())]"
Will select all nodes which are non-text node.
Here in the given example: bookstore and book are also non-text nodes as they does not have any text of their own, though their children do have text.

like image 79
NileshChauhan Avatar answered Nov 22 '25 16:11

NileshChauhan