Quote Originally Posted by Sonny Falk View Post
Note also that when using AddElementNS you don't necessarily even need the workaround with adding the namespace declaration manually using AddAttribute. Because you're using the namespace aware methods, the XML classes now properly understand that you're using namespaces, and the resulting XML will be accordingly.
Wow! Confirmed to work, as I until now didn't expect.

Reminds me of the problems many websites experienced when IE7 was released a few years ago. For IE6 there is several hacks to make it behave like other browsers, and as expected for a browser according to specs. Then the new IE unexpectedly started to interpret html and css more properly. Whole sites broke down and became unreadable, until they checked for browser version too, not just IE.

What I for sure didn't expect was that I should use the xxxNS methods also when adding elements in the default namespace. Lesson: The default namespace is also and actually a namespace. The namespace-aware methods MUST be used.

For other namespaces (other than the default) I still want to add the xmlns:mynstoken attribute to the root or a parent, as a declaration, because else the attribute
Code:
 xmlns:mynstoken="http://sparhell.no/my-special-ns"
is added to every such element. It becomes:
Code:
<myelement xmlns="http://sparhell.no/my-special-ns">content</myelement>
instead of the possibly shorter
Code:
<mynstoken:myelement>content</mynstoken:myelement>
And MSXML6 finally serializes empty elements correctly using self-closing tags, like <tag/>! Today
I'm impressed. Very impresed.

Thank you very much for the explaination! Everything now works fine.