Iterate through an xml file for a selected node

后端 未结 1 1013
轻奢々
轻奢々 2021-01-29 03:53

i have an xml file called image.xml

 

 
     0
     0

        
相关标签:
1条回答
  • 2021-01-29 04:18

    I'm not sure if I understood it correctly, but try something like this:

    XmlDocument xml = new XmlDocument();
    xml.LoadXml("<Image>..."); // or xml.Load("yourfile.xml");
    
    string name = "Gallery1";
    XmlElement gallery = xml.SelectSingleNode("//" + name) as XmlElement;
    if(gallery == null)
    {
        gallery = xml.CreateElement(name);
        gallery.InnerText = "1";
        xml.DocumentElement.AppendChild(gallery);
    }
     else
    {
       gallery.InnerText = (Int32.Parse(gallery.InnerText) + 1).ToString();
    }
    
    0 讨论(0)
提交回复
热议问题