Hello,
I have it and I want to change and replace attributes.
Works well with XmlDocument. Please see attached test files.
Product_xml.TXT
Product_xml_NEW.TXT
Product_Complex_xml.TXT
Convert_to_XDocument.txt
private void btnXMLReplaceAttribute_Click(object sender, EventArgs e)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"..
XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName("LABEL");
foreach (XmlNode item in xmlNodeList)
{
XmlAttributeCollection xmlAttributeCollection = item.Attributes;
XmlNode xml = xmlAttributeCollection.GetNamedItem("value");
//xml.InnerText = (int.Parse(xml.InnerText) - 1).ToString();
xml.InnerText = "NEW String";
}
xmlDocument.Save(@"..
}
Two questions.
How can I solve this with XDocument? I need XDocument!
How can I filter it if the element name occurs multiple times. I only want to change the CAD elements
<POSITION>
<ALTLABEL value="" />
<ANGLE value="0" />
<LABEL value="M22" /> // YES do it!
<SIDE2>
<LABEL value="GlobalM22" /> // No not
<POSITIONS>
<POSITION>
// --------
<ROOT>
<PANEL_CAD>
<XSIZE value="230" />
<YSIZE value="170" />
<SIDE1>
<POSITIONS>
<POSITION>
<ALTLABEL value="" />
<ANGLE value="0" />
<LABEL value="M22" />
<XOFFSET value="0" />
<XPOS value="69.897" />
<YOFFSET value="0" />
<YPOS value="86.827" />
</POSITION>
<POSITION>
<ALTLABEL value="" />
<ANGLE value="0" />
<LABEL value="M22" />
<XOFFSET value="0" />
<XPOS value="69.897" />
<YOFFSET value="0" />
<YPOS value="86.827" />
</POSITION>
</POSITIONS>
</SIDE1>
<SIDE2>
<LABEL value="GlobalM22" />
<POSITIONS>
<POSITION>
<ALTLABEL value="" />
<ANGLE value="0" />
<LABEL value="M22" />
<XOFFSET value="0" />
<XPOS value="69.897" />
<YOFFSET value="0" />
<YPOS value="86.827" />
</POSITION>
<POSITION>
<ALTLABEL value="" />
<ANGLE value="0" />
<LABEL value="M22" />
<XOFFSET value="0" />
<XPOS value="69.897" />
<YOFFSET value="0" />
<YPOS value="86.827" />
</POSITION>
</POSITIONS>
</SIDE2>
</PANEL_CAD>
</ROOT>
Thank you for your help and the solutions.