Xml element declaration with the namespace attributes

M

Martin Honnen

I need to form an xmlelement like the declaration below:
<message xmlns="http://abcd.com" xmlns:s2s="http://abcd.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://abcd.com message.xsd">

Here is an example

const string xmlns = "http://www.w3.org/2000/xmlns/";
XmlDocument xmlDocument = new XmlDocument();
XmlElement message = xmlDocument.CreateElement("message",
"http://abcd.com/");
XmlAttribute s2sNs = xmlDocument.CreateAttribute("xmlns", "s2s",
xmlns);
s2sNs.Value = "http://abcd.com/";
message.SetAttributeNode(s2sNs);
XmlAttribute xsiSchemaLocation =
xmlDocument.CreateAttribute("xsi", "schemaLocation",
"http://www.w3.org/2001/XMLSchema-instance");
xsiSchemaLocation.Value = "http://abcd.com message.xsd";
message.SetAttributeNode(xsiSchemaLocation);
xmlDocument.AppendChild(message);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top