XML Document Question

I've got the following XML:
<Widgets   xmlns="http://www.tryme.com">
  <Widget name="Pipe"  caption="Pipe">
    <Filters>
      <Filter member="Kind" operator="IsEqualTo" value="2" valueType="Int32" />
    </Filters>
    <Access>
      <Field name="Code" lock="true" />
      <State condition="Id = 0">
        <Field name="Code" lock="false" />
      </State>
      <State condition="IncreseMethodCode = 1">
        <Field name="Increse" lock="true" />
      </State>
      <State condition="IncreseMethodCode = 2">
        <Field name="IncresePeriodInMonths" lock="true" />
      </State>
    </Access>
  </Widget >
</Widgets>

Open in new window

I need to get a collection of the 'States' for the Widget with name "Pipe". I've got this code from the online sample, but I'm trying to get a neat way of getting the 'States' in one go.
   XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("bk", "http://www.tryme.com");
            string xPathString = "//bk:Widgets/bk:Widget[@name='Pipe']";

            XmlNode xmlNode = doc.DocumentElement.SelectSingleNode(xPathString, nsmgr);
            XmlNodeList list = xmlNode.ChildNodes;
            return list ;

Open in new window

Silas2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
You could use the SelectNodes() method instead of SelectSingleNode() with the XPath which selects the States:
string xPathString = "//bk:Widgets/bk:Widget[@name='Pipe']/bk:State";
that will give you the list of State nodes, so you won't need to deal with the ChildNodes collection anymore.
Silas2Author Commented:
Thanks for having a look for me. I tried that and:
//bk:Widgets/bk:Widget[@name='Pipe']/bk:States
(with 's' at the end)
and :
//bk:Widgets/bk:Widget[@name='Pipe']//bk:Access/bk:States
but neither seems to yield anything, is it because <States> is nested in Access?
zc2Commented:
My bad, skipped the Access node. Please try:
//bk:Widgets/bk:Widget[@name='Pipe']/bk:Access/bk:State

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Silas2Author Commented:
Thanks, that's got it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.