469,271 Members | 1,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Is there XmlDecode/XmlEncode?

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&ltmessage/>

I want to convert this to: <message>quick brown fox</message>

How?
(I don't think XmlConvert handles this.)

regards,
T

May 24 '07 #1
3 16304
"Fallen" <sw***********@gmail.comwrote in message
news:11*********************@b40g2000prd.googlegro ups.com...
>I have a string containing XML embedded withing another XML document
as an attribute value. This is what the string looks like:
&lt;message&gt;quick brown fox&ltmessage/&gt;

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="&lt;message&gt;quick brown
fox&ltmessage/&gt;"/>
string embeddedXml =
doc.DocumentElement["child"].Attributes["attributeWithXML"].Value;
Console.WriteLine(embeddedXml);

What prints out?
--
John Saunders [MVP]
May 24 '07 #2
T
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.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Xml;
  3.  
  4. class Starter {
  5. public static void Main(string[] args){
  6. XmlDocument doc = new XmlDocument();
  7. string xml = "<d><child attributeWithXML=\"&lt;message&gt;quick
  8. brown fox&lt;/message&gt;\" /></d>";
  9. doc.LoadXml(xml);
  10. string embeddedXml =
  11. doc.DocumentElement["child"].Attributes["attributeWithXML"].Value;
  12. Console.WriteLine(embeddedXml);
  13. }
  14. }
  15.  
On May 24, 4:11 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:
"Fallen" <sw.tejasvi...@gmail.comwrote in message

news:11*********************@b40g2000prd.googlegro ups.com...
I have a string containing XML embedded withing another XML document
as an attribute value. This is what the string looks like:
&lt;message&gt;quick brown fox&ltmessage/&gt;
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="&lt;message&gt;quick brown
fox&ltmessage/&gt;"/>
string embeddedXml =
doc.DocumentElement["child"].Attributes["attributeWithXML"].Value;
Console.WriteLine(embeddedXml);

What prints out?
--
John Saunders [MVP]
May 24 '07 #3
"T" <sw***********@gmail.comwrote in message
news:11*********************@h2g2000hsg.googlegrou ps.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]
May 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.