More flexible DTD solution needed

C

Collin VanDyck

Hello!

I'm relatively new to writing DTDs, so be gentle with me :)

I'm writing a DTD to validate XML documents that script my product which
managed XHTML.

I want to use the DTD to enforce basic, high level structure but I don't
want to account for every single type of element that could be in the
script document.

For instance, I want to allow this:

<script>
<add-page>
<name>testPage</name>
<content>
ALL SORTS OF XHTML CONTENT GOES HERE
</content>
</add-page>
</script>

In my DTD I specify the rules for the script, add-page, name, and
content elements. However, I want to allow all sorts of markup in the
content element without having to account for it in the DTD.

In other words, if the user supplies:

<script>
<add-page>
<name>testPage</name>
<content>
<b>Hi!</b>
</content>
</add-page>
</script>

Then I get an error when validating because 'b' was not defined as an
element.

Any ideas, or is this not possible using DTD ?

thanks,
Collin
 
P

Peter Flynn

Collin said:
Hello!

I'm relatively new to writing DTDs, so be gentle with me :)

I'm writing a DTD to validate XML documents that script my product which
managed XHTML.

I want to use the DTD to enforce basic, high level structure but I don't
want to account for every single type of element that could be in the
script document.

You can't. Validation means accounting for every single element.
For instance, I want to allow this:

<script>
<add-page>
<name>testPage</name>
<content>
ALL SORTS OF XHTML CONTENT GOES HERE
</content>
</add-page>
</script>

That's different. Depending on what you really mean, you could either

a) write a DTD which allowed XHTML mixed content, equivalent to the
content model for P, for example

b) write a DTD which allowed any arbitrary mix of XHTML element types
(so it would never actually be valid XHTML in there, just a jumble.

(a) is easy. (b) is not so easy, because you still have to declare the
element types and provide them with content models.
Any ideas, or is this not possible using DTD ?

You either want valid XML or you don't. If you want it valid, it has to
conform to a DTD or Schema, so you have to write one which it can be
validated against. If you don't want to do that, you can't have valid
XML, just well-formed XML. Your call.

///Peter
 
T

Tommaso Torti

Richard Tobin said:
Right, it's not possible.

It can be done with XML Schemas though.

-- Richard

Richard, can you explain this point with more details ?
Please... ;-)

Tommaso
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top