How to use XML namespace prefixes without xmlns="..." everywhere? (.NET)

Posted by LonelyPixel on Stack Overflow See other posts from Stack Overflow or by LonelyPixel
Published on 2010-04-04T14:08:56Z Indexed on 2010/04/04 14:13 UTC
Read the original article Hit count: 116

Filed under:
|
|
|

The subject is probably too short to explain it...

I'm writing out XML files with no namespace stuff at all, for some application. That part I cannot change. But now I'm going to extend those files with my own application-defined element names, and I'd like to put them in a different namespace. For this, the result should look like this:

<doc xmlns:x="urn:my-app-uri">
  <a>existing element name</a>
  <x:addon>my additional element name</x:addon>
</doc>

I've used an XmlNamespaceManager and added my URI with the prefix "x" to it. I've also passed it to each CreateElement for my additional element names. But the nearest I can get is this:

<doc>
  <a>existing element name</a>
  <addon xmlns="urn:my-app-uri">my additional element name</addon>
</doc>

Or maybe also

  <x:addon xmlns:x="urn:my-app-uri">my additional element name</x:addon>

So the point is that my URI is written to every single of my additional elements, and no common prefix is written to the document element where I'd like to have it.

How can I get the above XML result with .NET?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Xml