Click here to Skip to main content
15,937,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all . I'm looking for advice .
I have an XML file , and my task is to change the attribute of node . But when i make this a have an error:
"Namespace Manager or XsltContext needed" .
My xml file :
XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://somelink.com">


my code :
C#
XmlDocument docreq = new XmlDocument();
    docrev.Load("Mynew.xml");
     XmlNode node = docreq.SelectSingleNode("soapenv:Envelope");
   node.Attributes[0].Value = "NEWLINK";
  using (TextWriter writer = new StreamWriter("Mynew.xml", false, Encoding.UTF8))
docreq.Save(writer);


How I can change the attribute to NEWLINK without this error?
Posted
Updated 13-Apr-15 21:35pm
v3
Comments
Sergey Alexandrovich Kryukov 13-Apr-15 10:20am    
Not clear. You are using a reader and only read. How can you change anything, where? What are you trying to achieve?
—SA
Andrey Golubtsov 13-Apr-15 10:33am    
I select node : XmlNode node = docreq.SelectSingleNode("soapenv:Envelope");
and in this node i want to change attribute xmlns:soapenv="http://somelink.com" .
I had: soapenv:envelope xmlns:soapenv="http://somelink.com"
I want to change it like : <soapenv:envelope xmlns:soapenv="NEWLINK">
Sergey Alexandrovich Kryukov 13-Apr-15 10:43am    
You can change some attribute only somewhere, in data or in the file. If a file, you need to write a file. Or you need to write something in data in memory.
—SA

1 solution

C#
XDocument xDocument = XDocument.Load("MyXml.xml");

XElement soapenvXElement = xDocument.Descendants().FirstOrDefault();

soapenvXElement.Value = "NEWLINK";
 
Share this answer
 
Comments
Andrey Golubtsov 13-Apr-15 10:59am    
This doesn't work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900