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 version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="">

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

How I can change the attribute to NEWLINK without this error?
Updated 13-Apr-15 21:35pm
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?
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="" .
I had: soapenv:envelope xmlns:soapenv=""
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.

1 solution

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

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

soapenvXElement.Value = "NEWLINK";
Share this answer
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