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

Subject is probably too short to explain this ...

I am writing XML files without any namespace elements for any application. That part that I can’t change. But now I'm going to expand these files with my application name names, and I would 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 used the XmlNamespaceManager and added my URI with the prefix "x" to it. I also passed it to each CreateElement element for my additional element names. But the closest I can get is:

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

Or maybe,

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

, , URI , , .

XML .NET?

+3
1

, DOM Level 2 Core, :

doc.documentElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:x", "urn:my-app-uri");

; , DOM Level 3 LS, xmlns.

, .NET XmlDocument , , .

+2

Source: https://habr.com/ru/post/1739760/


All Articles