Solved

CDATA Best Practices

Posted on 2004-08-26
3
465 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 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, …
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 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

7 Experts available now in Live!

Get 1:1 Help Now