problem writing xml

  • Thread starter Thread starter Aahz
  • Start date Start date
A

Aahz

Hello,

I need to write xml file ( using c#) with some elements inside that
actually contains html code, like this:

'Moscow <p></p><a href="www.google.com"><img
src="gallery/t20.jpg" border="0" /><br /> Red Sqare </
a>

Instead of that every time I got this:

Moscow <p></p><a
href='www.google.com'><img src='/gallery/t20.jpg' border='0' /
><br /> Red Sqare </a>

can someone please explain what I need to replace with what and where
to do that???

Thank you

P.S.
here is code:

<br /> Red Sqare </a>"

xmlfile = new XmlDocument();
xmlfilename= Server.MapPath("cities.xml");
writer = new XmlTextWriter(xmlfilename,
System.Text.Encoding.UTF8);
writer.Formatting =
System.Xml.Formatting.Indented;
writer.WriteStartDocument();
writer.WriteComment("this is a comment");
writer.WritetartElement("places");
writer.WriteAttributeString("html",city);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();

writer.Flush();
writer.Close();
 
I need to write xml file ( using c#) with some elements inside that
actually contains html code, like this:

'Moscow <p></p><a href="www.google.com"><img
src="gallery/t20.jpg" border="0" /><br /> Red Sqare </
a>

Instead of that every time I got this:

Moscow &lt;p&gt;&lt;/p&gt;&lt;a
href='www.google.com'><img src='/gallery/t20.jpg' border='0' /
&gt;&lt;br /&gt; Red Sqare &lt;/a&gt;

can someone please explain what I need to replace with what and where
to do that???

Well, it looks like you're using the HTML as an attribute within
another element - so it's being escaped for you, correctly. If you
want to include that text directly, you should use XmlWriter.WriteRaw.

Jon
 
If you want to include that text directly, you should use XmlWriter.WriteRaw.

If the HTML is valid XHTML; if it isn't, then you will need a CDATA
section to wrap the HTML.

Marc
 
If the HTML is valid XHTML; if it isn't, then you will need a CDATA
section to wrap the HTML.

Absolutely. Even if it *is* valid XHTML, the OP really needs to decide
whether he wants that data to appear as part of the XML structure, or
whether it's just text which *happens* to be XML.

Jon
 
Back
Top