Subject: XPath to get node with sons with specific text
From: Andy Kohn <andydev@xxxxxxxxx>
Date: Mon, 10 Aug 2009 18:34:37 +1000
|
Using XPath, is it possible for me to select a whole branch by
searching for the first child to contain some specific text.
For example for the following XML:
<List>
<Contact>
<Name>test1test</Test>
<Data>sample data</Data>
<Data>sample</Data>
<Data>sample 123</Data>
</Contact>
<Contact>
<Name>test133</Test>
<Data>sample data</Data>
</Contact>
<Contact>
<Name>test2test</Test>
<Data>sample data</Data>
<Data>sample</Data>
<Data>sample 123</Data>
</Contact>
</List>
If I search for "test1" I want from the Xpath to return the first
<Contact> and the second <Contact>, including all child nodes (<Name>
and <Data>):
<Contact>
<Name>test1test</Test>
<Data>sample data</Data>
<Data>sample</Data>
<Data>sample 123</Data>
</Contact>
<Contact>
<Name>test133</Test>
<Data>sample data</Data>
</Contact>
Something like:
//Name[contains(.,'Ab')]
But this returns only the Name node, and not all the childs.
Thanks,
Andy.
|