Solved

CDATA Best Practices

Posted on 2004-08-26
3
463 Views
Last Modified: 2011-09-20
I have a need to dynamically generate xml from a sqlserver database and send it to a users browser with an applied xsl sylesheet. Currently I am putting all data in CDATA tags, I guess just to make sure anything will display. Is there anthing wrong with CDATA or are there any considerations I should address? My xml looks like this:

<Applicant>
      <ID>2544</ID>
      <Table>
            <TableName><![CDATA[Basic Info]]></TableName>
            <Field>
                  <DataType><![CDATA[Text]]></DataType>
                  <FieldName><![CDATA[First Name]]></FieldName>
                  <Data>
                        <Value><![CDATA[John]]></Value>
                  </Data>
            </Field>
            <Field>
                  <DataType><![CDATA[Text]]></DataType>
                  <FieldName><![CDATA[Last Name]]></FieldName>
                  <Data>
                        <Value><![CDATA[Smith]]></Value>
                  </Data>
            </Field>
      </Table>
      <Table>
            <TableName><![CDATA[Phone Numbers]]></TableName>
            <Field>
                  <DataType><![CDATA[Text]]></DataType>
                  <FieldName><![CDATA[US Phone Number]]></FieldName>
                  <Data>
                        <Value><![CDATA[503-5455-6644]]></Value>
                        <Value><![CDATA[503-699-5633]]></Value>
                        <Value><![CDATA[503-668-8850]]></Value>
                  </Data>
            </Field>
</Applicant>
0
Comment
Question by:paulfryer
  • 2
3 Comments
 
LVL 1

Author Comment

by:paulfryer
ID: 11904207
Note: I forgot to include the ending </table> tag on the last table.
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 500 total points
ID: 11904401
If the data is coming from SQL Server, and it's not escaped, then it's probably good practice to use CDATA, because values like:

Jim & Ron's Oyster Bar

will cause you grief.  If the field is not going to contain markup characters (ie: you know it's a phone number with digits and hyphens only), then you don't really need the CDATA. If the field will contain HTML markup, you may have special considerations...depending on how you're using the XML.

Regards,
Mike Sharp
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 11904417
By the way, in case you don't know about it, you might look at SQL XML 3.0 for what it can do for you here.

Regards,
Mike Sharp
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XML and javascript 14 79
JAXB error help 2 44
CRM 2011 Add a MsgBox  to replace an Error Message 4 108
XML to SQL Table using c# 5 45
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

14 Experts available now in Live!

Get 1:1 Help Now