Solved

XmlDocument Load xml

Posted on 2010-11-11
1
683 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

13 Experts available now in Live!

Get 1:1 Help Now