Solved

CDATA Best Practices

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

809 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