Solved

CDATA Best Practices

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JPA XML tag definition 2 67
SQL Remove Elements from XML 6 41
How do i send an api key in a request header 3 68
XML Data Missing in PHP SimpleXML 8 61
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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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