Solved

XmlDocument Load xml

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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, …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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