Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2005, 03:56 AM
Registered User
 
Join Date: Apr 2005
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
 
Old April 19th, 2005, 04:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old April 6th, 2006, 02:26 PM
Registered User
 
Join Date: Apr 2006
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
 
Old April 6th, 2006, 03:28 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old July 12th, 2006, 08:15 AM
Registered User
 
Join Date: Jul 2006
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"/>






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.