tags:

views:

185

answers:

3

I have a string

<entry key="Provider">Comcast Cable Communications, Inc.</entry>
<entry key="Challenged">No</entry>

I need to call the

using xmlwriter.WriteElementString I need to what the string mentioned earlier. Problem here is the xwriter.WriteElementString will escape all "<" and ">" symbols with &lt and &gt. I have checked MSDN to see if there is a way to disable it, but have not found an answer. Is there a way to disable the auto-escape features?

A: 

Can you show the XML you'd like to have? Are you trying to write XML inside of XML? Something like this:

<outer>
    <entry key="Provider">Comcast Cable Communications, Inc.</entry>
    <entry key="Challenged">No</entry>
</outer>

In that case, you don't want to use WriteElementString. Use one of the overloads of XmlWriter.WriteNode.

John Saunders
I am builing the xml from ad adbo.data reader . one of the column has xml data. That data need to be written to the xml element without escpases.Writenode only help if XmlTextReader is used
Ibrar Afzal
What is the data type of the column? varchar or something?
John Saunders
The datatype is a varchar. However I am appending all the contenct from the datareader to a stringbuilder object. once all the data is gathered from the 8 column in the dataready. I write the string to the xml. The problme with xmlwirter.writenode is that it requires a xmlreader as one of the parameter in the methods. I am not reading data from xmlready to begin with. Hence, this method call would not apply. Please correct me if I am wrong.
Ibrar Afzal
@Ibrar: since the column is varchar, you're ok. If you were using SQL Server 2005 or later, I'd suggest you use a column with the "XML" datatype. In that case, you can retrieve an actual `XmlReader` from the database for each column. That would have allowed you to use `WriteNode`.
John Saunders
+2  A: 

calling xmlwriter.writeraw fixed the problem.

Ibrar Afzal
Please edit your original question to add this information, then delete this answer.
John Saunders
JMarsch
@John: If he does that, then he will never be able to mark the question "answered" and it will always negatively impact his "percent accepted" score. Wouldn't the correct thing be for him to leave this entry in place and mark it as the answer?
JMarsch
@JMarsch: good suggestion. @Ibrar: please accept this answer. Thanks for posting it. It tells readers what the ultimate solution was.
John Saunders
@Ibrar: you should accept this answer, even if it's your own answer. Click the check mark under the number.
John Saunders
A: 

Is that the actual XML you are trying to write? (not a literal inside of XML)?

Try this:


xmlWriter.WriteStartElement("entry");
xmlWriter.WriteAttributeString("key", "Provider");
xmlWriter.WriteValue("Comcast Cable Communications, Inc.")
xmlWriter.WriteEndElement()

JMarsch