Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Thu, 7 Feb 2008 01:52:47 -0800 (PST),    group: microsoft.public.xsl        back       


xpath to select all the elements in XML with one exception only   
Hi

I need an efficient xpath 2.0 expressions to apply it to the following
input xml

<tag1>
    <tag2>
.........  many elements here
    </tag2>
    <tag3>
           <tag4>  a number here</tag4>
           .........  many elements here
    </tag3>
    <tag3>
           <tag4>  >  a number here </tag4>
           .........  many elements here
    </tag3>
           ..... many tag3 elements here
</tag1>

I need to get all the data in that xml except for the tag3 elements I
need to choose just one whose <tag4> value is equal to a certain value

Thanks

Mahmoud
date: Thu, 7 Feb 2008 01:52:47 -0800 (PST)   author:   unknown

Re: xpath to select all the elements in XML with one exception only   
khalil_mi@hotmail.com wrote:
> Hi
> 
> I need an efficient xpath 2.0 expressions to apply it to the following
> input xml
> 
> <tag1>
>     <tag2>
> .........  many elements here
>     </tag2>
>     <tag3>
>            <tag4>  a number here</tag4>
>            .........  many elements here
>     </tag3>
>     <tag3>
>            <tag4>  >  a number here </tag4>
>            .........  many elements here
>     </tag3>
>            ..... many tag3 elements here
> </tag1>
> 
> I need to get all the data in that xml except for the tag3 elements I
> need to choose just one whose <tag4> value is equal to a certain value
> 
> Thanks
> 
> Mahmoud


It's not clear what do you mean. Provide desired result please.

-- 
Oleg
date: Thu, 07 Feb 2008 13:28:53 +0200   author:   Oleg Tkachenko

Re: xpath to select all the elements in XML with one exception only   
On Feb 7, 12:28 pm, Oleg Tkachenko  wrote:
> khalil...@hotmail.com wrote:
> > Hi
>
> > I need an efficient xpath 2.0 expressions to apply it to the following
> > input xml
>
> > <tag1>
> >     <tag2>
> > .........  many elements here
> >     </tag2>
> >     <tag3>
> >            <tag4>  a number here</tag4>
> >            .........  many elements here
> >     </tag3>
> >     <tag3>
> >            <tag4>  >  a number here </tag4>
> >            .........  many elements here
> >     </tag3>
> >            ..... many tag3 elements here
> > </tag1>
>
> > I need to get all the data in that xml except for the tag3 elements I
> > need to choose just one whose <tag4> value is equal to a certain value
>
> > Thanks
>
> > Mahmoud
>
> It's not clear what do you mean. Provide desired result please.
>
> --
> Oleg- Hide quoted text -
>
> - Show quoted text -

If the input xml is:
<tag1>
<tag2>
.........  many elements here
</tag2>
<tag3>
<tag4>  5</tag4>
.........  many elements here
</tag3>
<tag3>
<tag4>  >  7 </tag4>
.........  many elements here
</tag3>

..... many tag3 elements here

</tag1>

 And I want to choose the tage3 whose tag4 is 7 then the desired
output is:

<tag1>
<tag2>
.........  many elements here
</tag2>
<tag3>
<tag4>  >  7 </tag4>
.........  many elements here
</tag3>
</tag1>

thanks

Mahmoud
date: Thu, 7 Feb 2008 03:37:38 -0800 (PST)   author:   unknown

Re: xpath to select all the elements in XML with one exception only   
khalil_mi@hotmail.com wrote:

> If the input xml is:
> <tag1>
> <tag2>
> .........  many elements here
> </tag2>
> <tag3>
> <tag4>  5</tag4>
> .........  many elements here
> </tag3>
> <tag3>
> <tag4>  >  7 </tag4>
> .........  many elements here
> </tag3>
> 
> ..... many tag3 elements here
> 
> </tag1>
> 
>  And I want to choose the tage3 whose tag4 is 7 then the desired
> output is:
> 
> <tag1>
> <tag2>
> .........  many elements here
> </tag2>
> <tag3>
> <tag4>  >  7 </tag4>
> .........  many elements here
> </tag3>
> </tag1>

XPath selects nodes in an existing documents, it does not change the 
document. Therefore if you select the root element 'tag1' in your 
example then it has all its children, you can't remove some of the 
children with XPath alone, you need XSLT for that.



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Thu, 07 Feb 2008 18:36:19 +0100   author:   Martin Honnen

Re: xpath to select all the elements in XML with one exception only   
Martin Honnen wrote:

> XPath selects nodes in an existing documents, it does not change the 
> document. Therefore if you select the root element 'tag1' in your 
> example then it has all its children, you can't remove some of the 
> children with XPath alone, you need XSLT for that.

However if you wanted to select only certain child elements of the root 
element tag1 then you can do that as follows:
   /tag1/*[not(self::tag3[not(tag4 = '7')])]
That selects all those child elements that are not 'tag3' elements not 
having a 'tag4' child element with contents '7'.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Thu, 07 Feb 2008 18:52:11 +0100   author:   Martin Honnen

Re: xpath to select all the elements in XML with one exception only   
On Feb 7, 12:52 pm, Martin Honnen  wrote:
> Martin Honnen wrote:
> > XPath selects nodes in an existing documents, it does not change the
> > document. Therefore if you select the root element 'tag1' in your
> > example then it has all its children, you can't remove some of the
> > children with XPath alone, you need XSLT for that.
>
> However if you wanted to select only certain child elements of the root
> element tag1 then you can do that as follows:
>    /tag1/*[not(self::tag3[not(tag4 = '7')])]
> That selects all those child elements that are not 'tag3' elements not
> having a 'tag4' child element with contents '7'.
>
> --
>
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

That was a very helpful snippet Martin thanks for that.
date: Wed, 19 Mar 2008 12:50:54 -0700 (PDT)   author:   unknown

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us