1

I have an XElement which contains the content that I want. However, I want to add a namespace prefix to only the ref elements. Is this possible in C#?

For example, the original XML looks like this:

<Root>
  <Element1 />
  <Element2 />
  <Element3>
    <Element3_Child1 />
    <Element3_Child2 />
  </Element3>
  <Element4 />
  <Element5>
    <Element5_Child1>
       <Element5_Child1_Child51 />
    </Element5_Child1>
  </Element5>
</Root>

I want to add a namespace prefix, so that the XML looks as below

<Root>
  <Element1 />
  <Element2 />
  <ns:Element3>
    <Element3_Child1 />
    <Element3_Child2 />
  </Element3>
  <Element4 />
  <ns:Element5>
    <ns:Element5_Child1>
       <Element5_Child1_Child51 />
    </Element5_Child1>
  </Element5>
</Root>
H H
  • 263,252
  • 30
  • 330
  • 514
EagerNoob
  • 101
  • 2
  • 13

1 Answers1

0

You can do as stated here : http://www.w3schools.com/xml/xml_namespaces.asp

<root
    xmlns:foo="http://www.example.org/foo"
    xmlns:bar="http://www.example.org/bar">

However, I'm pretty sure you'll need a valid URI and that you can't "fake" one. Otherwise, the namespace will be invalid. But you can test and let us know.

crogeniks
  • 46
  • 7