Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 08:48 AM
X. Lee
Guest
 
Posts: n/a
Default add CDATA element to an xml schema?

I am creating an xml schema, and I want one of the elements to include
html text. Therefore, I want to make that element a CDATA elements so
that it can accept html tags as part of it's value. I'm having
trouble doing this though. Can anyone give me a sample of how to do
that?

so if this is my xml instance:

<root>
<element><!CDATA[something]]></element>
</root>

how would I create an xml schema so that my instance is valid against
that schema?
  #2  
Old July 20th, 2005, 08:48 AM
Richard Tobin
Guest
 
Posts: n/a
Default Re: add CDATA element to an xml schema?

In article <2e603003.0410250924.4ed26fe7@posting.google.com >,
X. Lee <xhiax@yahoo.com> wrote:
[color=blue]
><root>
><element><!CDATA[something]]></element>
></root>[/color]
[color=blue]
>how would I create an xml schema so that my instance is valid against
>that schema?[/color]

CDATA sections are just a mechanism for escaping character data, so
as far as the schema is concerned it's no different from an element
containing ordinary text.

There's no way to *require* that the user use a CDATA section.

-- Richard
  #3  
Old July 20th, 2005, 08:50 AM
Peter Flynn
Guest
 
Posts: n/a
Default Re: add CDATA element to an xml schema?

X. Lee wrote:
[color=blue]
> I am creating an xml schema, and I want one of the elements to include
> html text.[/color]

You mean HTML markup? In general, this is A Bad Idea. If the markup is
important, represent it in the schema. If it's not, remove it.
[color=blue]
> Therefore, I want to make that element a CDATA elements so
> that it can accept html tags as part of it's value. I'm having
> trouble doing this though. Can anyone give me a sample of how to do
> that?[/color]

You can't do this in XML. If you want to declare CDATA content you have
to use SGML instead, eg

<!element foo - - CDATA>

but even so most SGML parsers will reject any attempt to use an end-tag
inside the element.
[color=blue]
> so if this is my xml instance:
>
> <root>
> <element><!CDATA[something]]></element>
> </root>
>
> how would I create an xml schema so that my instance is valid against
> that schema?[/color]

Doing it that way (with a manually-inserted CDATA Marked Section) is fine
(except you're missing an open-square bracket before the keyword CDATA).
The instance will always be valid, because the parser will suspend the
recognition of < and & until it encounters ]]>.

///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles