Silas2
asked on
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>
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 ;
ASKER
Thanks for having a look for me. I tried that and:
//bk:Widgets/bk:Widget[@na me='Pipe'] /bk:States
(with 's' at the end)
and :
//bk:Widgets/bk:Widget[@na me='Pipe'] //bk:Acces s/bk:State s
but neither seems to yield anything, is it because <States> is nested in Access?
//bk:Widgets/bk:Widget[@na
(with 's' at the end)
and :
//bk:Widgets/bk:Widget[@na
but neither seems to yield anything, is it because <States> is nested in Access?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that's got it.
string xPathString = "//bk:Widgets/bk:Widget[@n
that will give you the list of State nodes, so you won't need to deal with the ChildNodes collection anymore.