I have a very frustrating issue which I'm hoping will actually be something extremely simple. Apologies in advance if my terminology in XML files is wrong.
Basically I have a fairly simple XML file, here is an extract of one node:
<Attr num="108" name="Title" desc="The title of this file." type="s" ord="1" value="Test Title">
I can read and write the value key of the node fairly easily, but only if the value key exists.
I can use this code to write values back to the file:
XmlNode node = xmlDoc.SelectSingleNode("//ma:Attr[@name='Title']/@value", ns);
node.Value = partname.Text;
xmlDoc.Save(sympath);
However, if the XML file has the node of the correct name, but does not have a value key then it fails. For example, in some files the XML looks like this:
<Attr num="108" name="Title" desc="The title of this file." type="s" ord="1">
So I'm going round and round in circles just trying to add value="something"
to that node if it doesn't already exist. Is there a way to do this? I can add child elements, but I just want to add the value in that string!
I have tried searching for an answer, but all the other similar issues seem to be about adding or modifying child elements.
Thank you,
Andrew