?
Solved

XmlDocument Load xml

Posted on 2010-11-11
1
Medium Priority
?
701 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
[X]
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
1 Comment
 
LVL 3

Accepted Solution

by:
xeonol earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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