> in vb.net I have this code:
> .....
> myNode= XmlDoc.CreateElement("aNode")
> <aNode xlink:href="foo" xmlns="">
That happends during serialization if there is an
xmlns="http://example.com/" declaration on an ancestor element. Thus if
you want to be aNode in a particular namespace then you need to use an
overload of CreateElement that allows you to set the namespace e.b.
myNode = XmlDoc.CreateElement("aNode", "http://example.com/");
That way the serialization will work as you want it and no xmlns="" will
occur.
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fSystemXmlXmlDocumentClassCreateElementTopic2.asp>
The namespace a node is in is determined when you create the node so
always use namespace aware methods to create an element or attribute if
namespaces matter.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Fede - 28 Apr 2006 13:21 GMT
> That happends during serialization if there is an
> xmlns="http://example.com/" declaration on an ancestor element. Thus if
[quoted text clipped - 3 lines]
> That way the serialization will work as you want it and no xmlns="" will
> occur.
the problem is that i don't want xmlns attribute in my xml neither empty
neither with a value, how can i do?
Martin Honnen - 29 Apr 2006 13:12 GMT
> the problem is that i don't want xmlns attribute in my xml neither empty
> neither with a value, how can i do?
Well then make sure there is no element in the DOM tree that is in a
namespace. If the serializer does e.g.
xmlns=""
when serializing your DOM tree then that means there is an element in
the DOM tree which is in a namespace.
So somewhere up the tree you have an element in a namespace, if you
don't want that then don't create it at all or remove it before serializing.
For instance with the code
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.AppendChild(xmlDocument.CreateElement("root"));
xmlDocument.DocumentElement.AppendChild(xmlDocument.CreateElement("child"));
xmlDocument.Save(Console.Out);
the result is
<root>
<child />
</root>
so you can see there is no xmlns="" declaration. However if the code is e.g.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.AppendChild(xmlDocument.CreateElement("root",
"http://example.com/2006/ns1"));
xmlDocument.DocumentElement.AppendChild(xmlDocument.CreateElement("child"));
xmlDocument.Save(Console.Out);
then the result is
<root xmlns="http://example.com/2006/ns1">
<child xmlns="" />
</root>
You can see that the creation of the element with tag name "child" is
the same in both examples, only the serialization differs as the parent
element is in a namespace in the second example. That means you have to
look at the ancestors of the element where you get xmlns="" and make
sure that the ancestor is in no namespace.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/