Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

XmlDocument Load xml

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

792 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