Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 19th, 2005, 03:56 AM
Registered User
 
Join Date: Apr 2005
Location: Headley Village, HANTS, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chrisjonmcdonald
Default XSD CDATA Section

Hi,

Is there a way to specify a CDATASection within XSD? I know my element content is going to contain values that need not to be parsed within my XML document, so want to ensure that the relevant elements contain CDATA sections.

cheers

Chris




-------------------
Chris
Reply With Quote
  #2 (permalink)  
Old April 19th, 2005, 04:26 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

Think of CDATA simply as an alternative way of escaping special characters. Writing <A><![CDATA[<&>]]></A> is exactly equivalent to writing <A>&lt;&amp;&gt;</A>. If there aren't any special characters, then CDATA is completely redundant: <A><![CDATA[ABC]]></A> is just a long-winded way of writing <A>ABC</A>. The receiving application should process both in exactly the same way, and so it shouldn't care which was used on input. The purpose of the schema is to control the logical structure of the document, not the choice of escaping conventions for character data.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 6th, 2006, 02:26 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

> The purpose of the schema is to control the
> logical structure of the document, not the choice
> of escaping conventions for character data.

Cool. Now look at it from a developer's point of view.

(1) Define XSD
(2) Generate classes using a 3rd party tool
(3) Convert class information to XML at runtime via a standard translator like XmlSerializer

See a problem? Without a way to tell the XSD that "this field here needs to be escaped," you are right back into hand-coding one portion or another of the pipeline.

If the XSD committee doesn't want to dirty its hands with CDATASection, it at least should provide a way to say "this field needs to be escaped." Which in the real world means the thing will be CDATA....

So the real answer to the original post is, "Sorry buddy, you're screwed because there is no way to do this with XSD."

Jim
Reply With Quote
  #4 (permalink)  
Old April 6th, 2006, 03:28 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

A serializer must apply escaping to all text nodes (either using &amp; and &lt; or using CDATA) unless it knows that they can't contain &, <, or ]]>.

It's probably just as easy for the serializer to look at the actual content of the text or attribute node to see whether it contains special characters as to look in the schema.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old July 12th, 2006, 08:15 AM
Registered User
 
Join Date: Jul 2006
Location: Wien, , Austria.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<xsd:element name="description" type="xsd:string" sql:field="description" sql:use-cdata="1"/>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is CDATA same as xsd:String rajat_aggarwal03 XML 2 October 24th, 2008 01:05 PM
Add a CDATA section; add nodeset to CDATA section kssudhish XSLT 3 January 3rd, 2008 07:13 AM
CDATA Section using XSLT misanaka XSLT 2 March 29th, 2007 06:53 PM
Problem with the CData Section while using Xslt Vered XSLT 2 September 21st, 2006 11:21 AM
CDATA section kai77 Beginning VB 6 0 October 31st, 2004 04:50 PM



All times are GMT -4. The time now is 03:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.