469,312 Members | 2,476 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

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?
Jul 20 '05 #1
2 13895
In article <2e**************************@posting.google.com >,
X. Lee <xh***@yahoo.com> wrote:
<root>
<element><!CDATA[something]]></element>
</root> how would I create an xml schema so that my instance is valid against
that schema?


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
Jul 20 '05 #2
X. Lee wrote:
I am creating an xml schema, and I want one of the elements to include
html text.
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.
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?
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.
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?


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_
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Isaac Councill | last post: by
reply views Thread by Dimitre Novatchev | last post: by
reply views Thread by Janne | last post: by
1 post views Thread by Stephan Wehner | last post: by
1 post views Thread by pshymon123 | last post: by
12 posts views Thread by Peter Michaux | last post: by
3 posts views Thread by Kenny | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.