Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XPath-Query should include also root >Thread Next - Re: XPath-Query should include also root (SOLUTION) Re: XPath-Query should include also rootTo: NULL Date: 11/13/2007 2:12:00 PM "Holger Boskugel" <news.post@v...> wrote in message news:OsrTi$WJIHA.4476@T...... > Hello, > > I have to parse different partial XML-nodes. I want > get root or a child node if it has a specified attribute. > But I get only childs at the moment. How can I get > also the root node if it has the attribute? > > Sample: > > a) > <MyTag MyAttribute='true'>MyText</MyTag> > > b) > <MyRoot> > <MyTag MyAttribute='true'>MyText</MyTag> > </MyRoot> > > c) > <MyRoot> > <MyParent> > <MyTag MyAttribute='true'>MyText</MyTag> > </MyParent> > </MyRoot> > > How can I query a) and b) for the attribute > MyAttribute ? > > Actually "//*[@MyAttribute]" works only for > childs (b, c). But I need it also for a) in the same > query like this expression : > > "Select the root or child or descendant which > has an attribute MyAttribute". > > Try:- //self::*[@MyAttribute] // is an abbreviation for /descendant-or-self::node() Therefore //* is /descendant-or-self::node()/child::* Hence this path can never select the root node. -- Anthony Jones - MVP ASP/ASP.NET | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
