A
A
anonymous2017-07-16 21:01:06
.NET
anonymous, 2017-07-16 21:01:06

What is the correct way to overwrite the value of an XML element in c#.net?

I want <fileOpen> </fileOpen>to change the value between, it doesn't work for some reason

XmlDocument doc = new XmlDocument();
                    doc.Load(GetFileName());
                    
                    //
                    //choose node for editing
                    XmlNode node = doc.SelectSingleNode($"/users/user[name={_PersonName} ]");    //node у меня null почемуто
                    XmlNode nodeFile = node.NextSibling;   //помогите
                    nodeFile = node.NextSibling;    
                    nodeFile.Value = openedFile;
                    doc.Save(GetFileName());

<users>
  <user>
    <name>dfg</name>
    <fileOpen>
    </fileOpen>
  </user>
</users>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavlo Barmak, 2017-07-16
@anonymouss

doc.SelectSingleNode([email protected]"users/user[name=""{_PersonName}""]").LastChild.InnerText = openedFile;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question