?
Solved

CDATA Best Practices

Posted on 2004-08-26
3
Medium Priority
?
471 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
[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
  • 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…
Suggested Courses

770 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