Reputation: 187
I've got an XmlNode that I create like this:
XmlNode nodeSecurity = xmlDoc.CreateNode(XmlNodeType.Element, "wsse", "Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
The result looks like this:
<wsse:Security />
The wsse-Namespace has already been declared by a parent node, so this node does not contain an "xmlns:wsse='...'"-attribute (unknown namespaces would have been declared in an automatic xmlns-attribute).
Now my problem: I need to declare a new namespace here, so the result looks like this:
<wsse:Security wsu:xmlns='....' />
I tried to add an attribute like this:
XmlNode attr = xmlDoc.CreateNode(XmlNodeType.Attribute, "wsu", "blabla");
nodeSecurity.Attributes.SetNamedItem(attr);
And the result is:
<wsse:Security p4:wsu="" xmlns:p4="blabla" />
Instead of:
<wsse:Security wsu:xmlns="blabla" />
What am I doing wrong here?
Upvotes: 0
Views: 1972
Reputation: 14231
Try this
XmlAttribute attr = xmlDoc.CreateAttribute("wsu", "xmlns", "namespace");
attr.Value = "blabla";
nodeSecurity.Attributes.Append(attr);
Result
<wsse:Security wsu:xmlns="blabla" xmlns:wsu="namespace" />
In this case, wsu:xmlns
is an attribute with the name xmlns
and prefix wsu
. The namespace belonging to the prefix set in the form xmlns:wsu
.
Upvotes: 1