473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 16478
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Cadwell | last post by:
We are encoding strings using XMLElement: private string XMLEncode(string val) { if(val.Length == 0) return string.Empty; XmlElement element = xmldoc.CreateElement("E"); element.InnerText =...
6
by: Joerg Battermann | last post by:
Hey there, mmmm does anyone know a library or anything I can use to convert plaintext to html real quick and vice-versa? Regex surely would do the trick to a certain level, but maybe there's...
9
by: Mantorok | last post by:
Hi all I have a plain text string, sometimes the string will contain special characters, how can I encode this string in xml format? Thanks Kev
3
by: Yobbo | last post by:
Hi All I have an ASP function in place to strip invalid chars out of a data store before I create an XML file of this data, but my function doesn't work on a certain set of chars. As far as I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.