Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Xpath query to return "NULL" values?

From: David Carlisle <david-news@---------.-----.--.-->
To: NULL
Date: 6/5/2009 11:36:00 PM
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'
> Found 3 nodes in stdin:
> -- NODE --
> 1
> -- NODE --
> 2
> -- NODE --
> 3
> mario@mike:~$ 
> 
> Is there a way to extract that NULL-valued node?
> 
> 	Mike

xpath doesn't have a NULL value, and text nodes never have an empty 
string as value. the third b has no child node at all.
It's actually rather rare to use text() in xpath, normally you'd just 
select the b nodes
the xpath /a/b  will select 4 b nodes with string values
"1" "2" "" "3"
In xpath 1 you can only have a node set so teh set of b nodes is the 
nearest you can get to this.
In xpath2 you could return the sequence of string values directly as
/a/b/string(.)

David


-- 
http://dpcarlisle.blogspot.com


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent