Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Xpath query to return "NULL" values? >Thread Next - Re: Xpath query to return "NULL" values? Re: Xpath query to return "NULL" values?To: NULL Date: 6/6/2009 9:55:00 AM On 2009-06-05, Martin Honnen <mahotrash@y...> wrote: > Mario Splivalo wrote: >> Here is my XML document: >> >> <a> >> <b>1</b> >> <b>2</b> >> <b></b> >> <b>3</b> >> </a> >> >> When I execute this XPath query against it: /a/b/text() >> >> I get only 1, 2 and 3: >> >> mario@mike:~$ echo "<a><b>1</b><b>2</b><b></b><b>3</b></a>" | xpath -e '/a/b/@id' > > Why /a/b/@id? There is no 'id' attribute in there at all. A typo, I'd say :) This is the correct Xpath query: ... | xpath -e '/a/b/text()' > > >> Is there a way to extract that NULL-valued node? > > There is an empty 'b' element in there. If you want to select all 'b' > elements then use the XPath > /a/b The 'trouble' is that I get XML portions, and I wanted 'clean' strings. I guess I could do another XPath query on return values, and then easily see wich ones are 'empty'. > if you only want the empty 'b' elements then use > /a/b[not(node())] That does me no good because I need to know on (in?) which position the empty element is. My actuall XML (shoul've written that in the OP) looks like this: <itemList> <item fieldName="name">Mario</item> <item fieldName="age">29</item> <item fieldName="height"></item> </itemList> What I'm trying to get is a rowset or table, since I'm doing this from postgres. So, my table would look like this: fieldName fieldValue name Mario age 29 height NULL The idea was to have two XPath queries on the original XML. First one ('/itemList/item/@fieldName') would extract all the attributes, and second one would extract all the 'values' ('/itemList/item/text()'). Now I guess I'll have to extract the nodes, as you've suggested, and then for each node chech if it's empty or not. Mike -- "I can do it quick. I can do it cheap. I can do it well. Pick any two." Mario Splivalo majk@f... | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
