Thanks John,
The following code does indeed print <message>quick brown fox</
message>.
But I know exactly where in the containing XML this string occurs. I
am able to extract this without the expense of parsing. I am looking
for a shortcut to unescape the embedded XML. But thanks the answer is
obvious from here.
[code]
using System;
using System.Xml;
class Starter {
public static void Main(string[] args){
XmlDocument doc = new XmlDocument();
string xml = "<d><child attributeWithXML=\"<message>quick
brown fox</message>\" /></d>";
doc.LoadXml(xml);
string embeddedXml =
doc.DocumentElement["child"].Attributes["attributeWithXML"].Value;
Console.WriteLine(embeddedXml);
}
}
[/code]
On May 24, 4:11 pm, "John Saunders [MVP]" <john.saunders at
[quoted text, click to view] trizetto.com> wrote:
> "Fallen" <sw.tejasvi...@gmail.com> wrote in message
>
> news:1179989178.951052.47690@b40g2000prd.googlegroups.com...
>
> >I have a string containing XML embedded withing another XML document
> > as an attribute value. This is what the string looks like:
> > <message>quick brown fox<message/>
>
> > I want to convert this to: <message>quick brown fox</message>
>
> > How?
>
> What happens if you do this:
>
> XmlDocument doc = new XmlDocument();
> doc.LoadXml(myWholeDocument);
> // Assuming <child attributeWithXML="<message>quick brown
> fox<message/>"/>
> string embeddedXml =
> doc.DocumentElement["child"].Attributes["attributeWithXML"].Value;
> Console.WriteLine(embeddedXml);
>
> What prints out?
> --
> John Saunders [MVP]
[quoted text, click to view] "T" <sw.tejasvi.sn@gmail.com> wrote in message
news:1180007476.237216.35420@h2g2000hsg.googlegroups.com...
> Thanks John,
>
> The following code does indeed print <message>quick brown fox</
> message>.
> But I know exactly where in the containing XML this string occurs. I
> am able to extract this without the expense of parsing. I am looking
> for a shortcut to unescape the embedded XML. But thanks the answer is
> obvious from here.
Glad to help.
The XmlDocument example was just a simple example to illustrate the fact
that the XML API's know how to escape and unescape XML. If you're only
looking for the one string, then an XPathDocument or even a simple XmlReader
would be much faster. Both of them understand how strings need to be
escaped.
--
John Saunders [MVP]