How to select nodes where text is not empty?

Hello ,

I'm looking in my sample xml for the sample node where both entities
(id and name) are set, in the sample output it is possible that name
entity can be empty, id is allways given.

sample xml
<samples>
	<sample>
		<id>1</id>
		<name>S1</name>
	</sample>
	<sample>
		<id>2</id>
		<name />
	</sample>
	<sample>
		<id>3</id>
		<name>S3</name>
	</sample>
	<sample>
		<id>4</id>
		<name />
	</sample>
</samples>

Expected result should be:

	<sample>
		<id>1</id>
		<name>S1</name>
	</sample>
	<sample>
		<id>3</id>
		<name>S3</name>
	</sample>


I can select the sample nodes in samples with "//sample", but I don't
know where I can restrict the result.

Thanks in advance
Volker
0
1/21/2009 8:36:27 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
922 Views

Similar Articles

[PageSpeed] 22

so  ... I found it ...

//sample[string-length(child::name) >0] works fine for me

I think this is my first self written XPATH Expression
0
1/21/2009 11:35:19 AM
Volker wrote:

> I'm looking in my sample xml for the sample node where both entities
> (id and name) are set, in the sample output it is possible that name
> entity can be empty, id is allways given.
> 
> sample xml
> <samples>
> 	<sample>
> 		<id>1</id>
> 		<name>S1</name>
> 	</sample>
> 	<sample>
> 		<id>2</id>
> 		<name />

   /samples/sample[normalize-space(name)]
or
   /samples/sample[name/text()]
should do.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
1/21/2009 12:07:22 PM
Reply:

Similar Artilces: