Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Simple Xpath question; retrieve attributes for specific parent

Question posted by: samsquared (Newbie) on July 1st, 2008 07:01 PM
I have an xml file that looks like this:

<DocBuild name="ABC">
<BldArea name="Components" product="ABC" area="C">
<BldItem name="Item1" module="mod1" tier="A" buildtype="auto"/>
<BldItem name="Item2" module="mod2" tier="B" buildtype="auto"/>
</BldArea>
<BldArea name="Core" product="ABC" area="C">
<BldItem name="Item5" module="mod5" tier="A" buildtype="auto"/>
<BldItem name="Item6" module="mod6" tier="B" buildtype="auto"/>
</BldArea>
</DocBuild>

I want to retrieve the name and tier attributes for BldItem elements whose BldArea is "Components". To get both attributes I can use something like BldItem/@name|BldItem/@tier but how do I specify that I just want those under 'Components'? There will be only one BldArea that contains name="Components" in the actual XML file.
jkmyoung's Avatar
jkmyoung
Moderator
797 Posts
July 2nd, 2008
07:03 PM
#2

Re: Simple Xpath question; retrieve attributes for specific parent
BidArea[@name = 'Components']/BldItem/@name | BidArea[@name = 'Components']/BldItem/@tier

or depending on context perhaps:
(BldItem/@name|BldItem/@tier)[../../@name='Components']

Reply
samsquared's Avatar
samsquared
Newbie
2 Posts
July 3rd, 2008
12:24 PM
#3

Re: Simple Xpath question; retrieve attributes for specific parent
Thank you - that did it! (I didn't try your second suggestion.)

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,758 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top XML Forum Contributors