I have an XML doc. For example this:
<Root xmlns:x="anynamespace" xmlns:html="htmlnamespace">
<x:Data>bla bla</x:Data>
</Root>
Here I got html namespace to format data. BUT value of element can be e.g.
<html:Font ...>bla bla</html:Font> or
bla <html:Font ...>bla</htmk:Font>
In my C# code I do this:
new XElement(main + "Data",myvalue); //main is namespace
As a result I got <x:Data><html:Font ...>bla bla etc. Linq replaced key tags with their text codes. So this is unacceptable.
Then i tried this:new XElement(main + "Data",XElement.Parse(myvalue));
There I got exception that prefix html didnt recognized.
Does anyone faced such problem? How did you solve that?
Usually you would not construct the contents from a string but rather simply construct the nodes using LINQ to XML e.g.
creates the XML
If you want to parse a fragment given as a string then perhaps the following approach helps:
That way I get