Simple Xpath question; retrieve attributes for specific parent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samsquared
    New Member
    • Jul 2008
    • 2

    #1

    Simple Xpath question; retrieve attributes for specific parent

    I have an xml file that looks like this:

    <DocBuild name="ABC">
    <BldArea name="Component s" 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="Component s" in the actual XML file.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    BidArea[@name = 'Components']/BldItem/@name | BidArea[@name = 'Components']/BldItem/@tier

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

    Comment

    • samsquared
      New Member
      • Jul 2008
      • 2

      #3
      Thank you - that did it! (I didn't try your second suggestion.)

      Comment

      Working...