XML structure issue

I have a main XML object I'm working with. I cannot figure out how to access parts of it.

 <FacetsData>
  <Collection name="CDDLALL" type="Group">
   <SubCollection name="CDDLALL" type="Row">
    <Column name="DPDP_ID">D0230< /Column>
    <Column name="Count">9< /Column>
   </SubCollection>
   <SubCollection name="CDDLALL" type="Row">
    <Column name="DPDP_ID">D1110< /Column>
    <Column name="Count">9< /Column>
   </SubCollection>
  </Collection>
 </FacetsData>

What I need to do is check every DPDP_ID, and if its value is D0230 then I leave the graph alone, everything else changes the graph to 1.

What I still have:

node = doc.DocumentElement;
nodeList = node.SelectNodes("/FacetsData/Collection/SubCollection");
for (int x = 0; x < nodeList.Count; x++) {
 if (nodeList[x].HasChildNodes) {
  for (int i = 0; i < nodeList[x].ChildNodes.Count; i++) {
   //This part I can't figure out how to get the name="" part of the xml
   //MessageBox.Show(oNodeList[x].ChildNodes[i].InnerText); get the "D0230","1"
   //part but not the "DPDP_ID","Count" part.
  }
 }
}
+3
source share
2 answers

Each node has a collection of attributes. You can do

nodeList[x].ChildNodes[i].Attributes["name"].value 

to get the value.

+4
source

Access to it is through oNodeList[x].ChildNodes[i].Attributes["name"].

+1
source

Source: https://habr.com/ru/post/1742271/


All Articles