C# Getting a node with attributes from SelectSingleNode

Posted by bdefreese on Stack Overflow See other posts from Stack Overflow or by bdefreese
Published on 2010-05-26T21:58:09Z Indexed on 2010/05/26 22:01 UTC
Read the original article Hit count: 201

Filed under:
|

Hi folks,

I am quite the n00b but lately I have been playing with parsing some XML data. I actually found a nice feature on this site where I can get to a specific node with a specific attribute by doing: docFoo.SelectSingleNode("foo/bar/baz[@name='qux']); However, the data looks like this:

<saving-throws>
        <saving-throw>
            <name>Fortitude</name>
            <abbr>Fort</abbr>
            <ability>Con</ability>
            <modifiers>
                <modifier name="base" value="2"/>
                <modifier name="ability" value="5"/>
                <modifier name="magic" value="0"/>
                <modifier name="feat" value="0"/>
                <modifier name="race" value="0"/>
                <modifier name="familar" value="0"/>
                <modifier name="feature" value="0"/>
                <modifier name="user" value="0"/>
                <modifier name="misc" value="0"/>
            </modifiers>
        </saving-throw>
        <saving-throw>
            <name>Reflex</name>
            <abbr>Ref</abbr>
            <ability>Dex</ability>
            <modifiers>
                <modifier name="base" value="6"/>
                <modifier name="ability" value="1"/>
                <modifier name="magic" value="0"/>
                <modifier name="feat" value="0"/>
                <modifier name="race" value="0"/>
                <modifier name="familar" value="0"/>
                <modifier name="feature" value="0"/>
                <modifier name="user" value="0"/>
                <modifier name="misc" value="0"/>
            </modifiers>
        </saving-throw>

And I want to be able to get the node with name=base but for each saving-throw node where childnode "abbr" = xx. Can I somehow do that in a single SelectSingleNode or am I going to have to stop at saving throw and walk through the rest of the tree?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml