0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that helped. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.