sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
jerry.xuddd's Avatar

Please help me with this XPath expression


Question posted by: jerry.xuddd (Guest) on November 12th, 2005 05:08 AM
Hi,
I have a xml file like this
<tab>
<category name="Software" > Test purpose
<subcategory name="Software">
<method url="addSoftware.aspx">Add</method>
<method url="editSoftware.aspx">Edit</method>
<method url="searchSoftware.aspx">Search</method>
</subcategory>
</category>
</tab>

Yesterday I asked a question about getting a node which has a specific child
node. However I realised that I need to get a node with a specific name and
has a specific child node as well. (e.g. a node's name is software and the
child node's name is software too)

I tried:
/tab/category[@name='software' and subcategory[@name='Software']]

But it did not give me any thing.

Would someone tell me the right way to do it?

Many Thanks

--
hello, please help
2 Answers Posted
Tommy Wang's Avatar
Guest - n/a Posts
#2: Re: Please help me with this XPath expression

for an xml document like below:
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
<data>
<tab>
<category name="Software" > Test purpose
<subcategory name="Software3">
<method url="addSoftware.aspx">Add</method>
<method url="editSoftware.aspx">Edit</method>
<method url="searchSoftware.aspx">Search</method>
</subcategory>
</category>
</tab>
<tab>
<category name="Software" > Test purpose
<subcategory name="Software5">
<method url="addSoftware.aspx">Add</method>
<method url="editSoftware.aspx">Edit</method>
<method url="searchSoftware.aspx">Search</method>
</subcategory>
</category>
</tab>
<tab>
<category name="Software2" > Test purpose
<subcategory name="Software2">
<method url="addSoftware2.aspx">Add</method>
<method url="editSoftware2.aspx">Edit</method>
<method url="searchSoftware2.aspx">Search</method>
</subcategory>
</category>
</tab>
</data>
to select node which category is "Software" and subcategory is "Software3"
/data/tab/category[@name="Software"]/subcategory[@name="Software3"]

"jerry.xuddd" <jerryxuddd@discussions.microsoft.com> wrote in message
news:91C2A4AC-793E-42B2-99F0-193261E590E3@microsoft.com...[color=blue]
> Hi,
> I have a xml file like this
> <tab>
> <category name="Software" > Test purpose
> <subcategory name="Software">
> <method url="addSoftware.aspx">Add</method>
> <method url="editSoftware.aspx">Edit</method>
> <method url="searchSoftware.aspx">Search</method>
> </subcategory>
> </category>
> </tab>
>
> Yesterday I asked a question about getting a node which has a specific
> child
> node. However I realised that I need to get a node with a specific name
> and
> has a specific child node as well. (e.g. a node's name is software and the
> child node's name is software too)
>
> I tried:
> /tab/category[@name='software' and subcategory[@name='Software']]
>
> But it did not give me any thing.
>
> Would someone tell me the right way to do it?
>
> Many Thanks
>
> --
> hello, please help[/color]


Peter Flynn's Avatar
Guest - n/a Posts
#3: Re: Please help me with this XPath expression

jerry.xuddd wrote:
[color=blue]
> Hi,
> I have a xml file like this
> <tab>
> <category name="Software" > Test purpose
> <subcategory name="Software">
> <method url="addSoftware.aspx">Add</method>
> <method url="editSoftware.aspx">Edit</method>
> <method url="searchSoftware.aspx">Search</method>
> </subcategory>
> </category>
> </tab>
>
> Yesterday I asked a question about getting a node which has a specific
> child node. However I realised that I need to get a node with a specific
> name and has a specific child node as well. (e.g. a node's name is
> software and the child node's name is software too)
>
> I tried:
> /tab/category[@name='software' and subcategory[@name='Software']]
>
> But it did not give me any thing.[/color]

/tab/category[@name='software'][subcategory[@name='Software']]

///Peter

 
Not the answer you were looking for? Post your question . . .
196,827 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,827 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors