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 rootTo: NULL Date: 11/13/2007 1:54:00 PM Holger Boskugel wrote: > 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 //*[descendant-or-self::*[@MyAttribute]], that selects elements at all level which themselves have an attribute MyAttribute or where a descendant has an attribute MyAttribute. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
