Solved

XmlDocument Load xml

Posted on 2010-11-11
1
681 Views
Last Modified: 2012-05-10
I have a stringbuilder object that I want to load into an Xmldocument.
I concat the nodes and elements within code. And I amhandling escape characters with CDATA in certain cases.

I need to know how to handle excape characters within a grouping.
I have an element called codes which could have one or more code's which has two attributes code and descriptionn. I need to handle if description has escape characters.

Should the concatanation of stringbuilder look something like this?
<code code="200" description="[CDATA[ORDER 100  & two]]"/>
<record>

<userid datatype='order'>151</webuserid>

<txtlastname datatype='order'><![CDATA[ANNIE]]></txtlastname>

<txtfirstname datatype='order'><![CDATA[SMITH]]></txtfirstname>

<txtaddress datatype='order'><![CDATA[79 TEST DR]]></txtaddress>

<txtcity datatype='order'><![CDATA[SOMEWHERE]]></txtcity>

<txtstate datatype='order'><![CDATA[NJ]]></txtstate>

<txtzip datatype='order'><![CDATA[08083]]></txtzip>

<codes datatype='order'>

<code code="100" description="ORDER 100"/>

<code code="200" description="ORDER 100  & two"/>

</codes>

</record>





Dim sb As New StringBuilder()

Dim XmlDoc As New System.Xml.XmlDocument

''''some logic to append values''''

sb.Append("'><![CDATA[")

   '''''append value''''''      

sb.Append("]]></")

XmlDoc.LoadXml(sb.ToString)

Open in new window

0
Comment
Question by:countrymeister
1 Comment
 
LVL 3

Accepted Solution

by:
xeonol earned 500 total points
ID: 34110002
If you want to escape the special characters in xml, a simple way is to replace them with escaped strings:
< -> < 
> -> > 
" -> &quot;
' -> &apos;
& -> &amp;

You can refer to http://weblogs.sqlteam.com/mladenp/archive/2008/10/21/Different-ways-how-to-escape-an-XML-string-in-C.aspx for some different ways.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now