ethar turky
asked on
XML MSXML2.DOMDocument30 selectNodes
Dear all,
I have following xml document:
I have following xml document:
<Site some_attributes="xxx">
<Page id="1"></Page>
<page id="2"></page>
<Style></Style>
</Site>
Need to use following C# code to select Site node[only] with its all attributes + Page id=2 [with its all child nodes].MSXML2.DOMDocument30 XMLSourceDataSingleDoc = new MSXML2.DOMDocument30();
XMLSourceDataSingleDoc.loadXML(XMLSiteSourceData.xml );
XMLSourceDataSingleDoc.selectNodes("xxxxxxxxxxx");
ASKER
Thanks for your reply,
the output I need is :
the output I need is :
<Site some_attributes="xxx">
<page id="1"></page>
</Site>
You can use the below XPath:
XmlNode node = root.SelectSingleNode(
"descendant::st:Site/st:Pa ge[@id='2' ]", nsmgr);
And get the outerXML
node.OuterXml
which shall give you
<Page id="2"></Page>
Then you may have to append the parent node's XML to get the desired value.
I shall check further if there is any other direct way to just the output that you desire (as per your last comment)
XmlNode node = root.SelectSingleNode(
"descendant::st:Site/st:Pa
And get the outerXML
node.OuterXml
which shall give you
<Page id="2"></Page>
Then you may have to append the parent node's XML to get the desired value.
I shall check further if there is any other direct way to just the output that you desire (as per your last comment)
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 for your great efforts...
You are welcome!
ASKER
/Site[Page[@id = 1]]. // node that you want to select and the filters within that node.
I tried using C# XMLDocument and SelectSingle node methods and it looks like below.
Open in new window
XML looks like below:Open in new window
You look at below reference for more help:
https://msdn.microsoft.com/en-us/library/cc189056%28v=vs.95%29.aspx
http://www.csharp-examples.net/xml-nodes-by-attribute-value/