Peter Bradley wrote:
Quote:
I'm trying to create an XML Document. This is what I want to end up with:
>
>
>
<?xml version="1.0" encoding="UTF-8" ?>
<epp xmlns="urn:iana:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0"
>
xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>example1.tld</domain:name>
<domain:name>example2.tld</domain:name>
<domain:name>example3.tld</domain:name>
</domain:check>
</check>
<unspec/>
<clTRID>ABC-12346</clTRID>
</command>
</epp>
Quote:
<?xml version="1.0" encoding="UTF-8" ?>
<epp />
>
I then load the string into an XmlDocument like this:
>
>
>
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNode root = doc.DocumentElement;
That is the wrong approach, the namespace of an element of attribute
node is determined when you create it and not by later adding namespace
declarations.
So you need e.g.
const string epp = "urn:iana:xml:ns:epp-1.0";
const string xsi = "http://www.w3.org/2001/XMLSchema-instance";
const string domain = "urn:iana:xml:ns:domain-1.0";
XmlDocument doc = new XmlDocument();
XmlElement eppEl = doc.CreateElement("epp", epp);
doc.AppendChild(eppEl);
XmlAttribute schemaLocation = doc.CreateAttribute("xsi",
"schemaLocation", xsi);
schemaLocation.Value = "urn:iana:xml:ns:epp-1.0 epp-1.0.xsd";
eppEl.SetAttributeNode(schemaLocation);
XmlElement command = doc.CreateElement("command", epp);
eppEl.AppendChild(command);
XmlElement check = doc.CreateElement("check", epp);
command.AppendChild(check);
XmlElement dCheck = doc.CreateElement("domain", "check",
domain);
command.AppendChild(dCheck);
and so on where you make sure you pass the namespace URI an element or
attribute belongs to to the CreateElement or CreateAttribute method.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/