Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone.

I have a problem developing code with xml and c#. I am trying to create the following Xml code:

XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.eurosur.gmv.com/">
   <soapenv:Header/>
   <soapenv:Body>
     xxxxxxxxxxxxxxx
   </soapenv:Body>


I am trying to create it, with the following code

C#
String sXml = @"<?xml version='1.0' encoding='utf-8'?> " +
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.dfdf.com/\"/>";
                
oXmlDocument.LoadXml(sXml);
XmlNamespaceManager omanager = new XmlNamespaceManager(oXmlDocument.NameTable);
omanager.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");
omanager.AddNamespace("ns2", "http://ws.dfdf.com/");
omanager.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
omanager.AddNamespace("ws", "http://ws.eurosur.gmv.com/");
                
XMLUtils oXMLUtils = new XMLUtils(oXmlDocument);
XmlNode oXmlBody = oXMLUtils.createNodeElement("soapenv:Body", "");
                oXMLUtils.insertAfter(oXmlDocument.SelectSingleNode("soapenv:Envelope", omanager), oXmlBody, null);

XmlNode oXmlCreate = oXMLUtils.createNodeElement("ws:updateArtefact", "");
                oXMLUtils.insertAfter(oXmlDocument.SelectSingleNode("soapenv:Envelope/Body", omanager), oXmlCreate, null);

XmlNode oXmlHeader = oXMLUtils.createNodeElement("soapenv:Header", "");
                oXMLUtils.insertAfter(oXmlDocument.SelectSingleNode("soapenv:Envelope", omanager), oXmlHeader, null);

return oXmlDocument;


But when I view the result, the prefix of the tags doesn´t appear.

But in the properties of the xmlnode it is assigned.

Can someone tell me what I am doing wrong??

Thank you very much
Posted

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