XML Document Question

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

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

Who is Participating?

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

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.

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:
(with 's' at the end)
and :
but neither seems to yield anything, is it because <States> is nested in Access?
My bad, skipped the Access node. Please try:

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

From novice to tech pro — start learning today.