Question : How to convert a stream with output escaping enabled to proper format XML that can be loaded in a XMLDocument object?

If I receive an input stream like below, how can I convert it to a proper XML?
I tried using String replace to replace the &lt; with < and &gt; with > but then if the node value also contains &lt; then that is also replaced and thus not able to load the XML.

<Commercial>
     &lt;Name&gt;Trust &lt;Commercial&gt; Company&lt;/Name&gt;
</Commercial>

I have to read this XML in a XMLDocument object and extract the <Name> element value which is "Trust <Commercial> Company".

This should be read as
<Commercial>
    <Name>Trust <Commercial> Company</Name>
</Commercial>

Would XSLT be required? A .net solution is also welcome.
Please help in suggesting a solution.

Thank you,
rdeveloper

Answer : How to convert a stream with output escaping enabled to proper format XML that can be loaded in a XMLDocument object?

That kinda sucks, especially in this case, where you get "<" and ">" as values as well as node wrappers.

If you replace "<" and ">" universally, then use DOM methods on the resulting XML, you will get an error when you try to get the value from "Commercial.Name". I suppose this could then be an indication that you need to re-format the "Commercial.Name" value by escaping any of the "bad" entities within the node's value, in this case by exchanging "<" and ">" for "<" and ">"...

Seems like a lot of work. I suppose you could "brute force" the replacement, but not before you replace all of the "<" and ">". Then you could pick apart the XML using JavaScript, taking what you want from the appropriate place within the string.

Either way, your work is cut out for you.
Random Solutions  
 
programming4us programming4us