Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-16-2002, 06:59 PM   PM User | #1
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
can a DTD specify that an element must contain data, or not exist at all

here's my DTD

Code:
<!DOCTYPE pubinfo [

<!ELEMENT pubinfo (publication)*>
<!ELEMENT publication (title,url?,date?,size?,source?,author?)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT url (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT size (#PCDATA)>
<!ELEMENT source (#PCDATA)>
<!ELEMENT author (#PCDATA)>

<!ATTLIST publication cat CDATA #REQUIRED>
<!ATTLIST publication sub CDATA #REQUIRED>
<!ATTLIST publication sba CDATA #REQUIRED>

]>

Most of the children of <publication> are optional, but I want to specify that, for example

<url />

is not allowed - each optional tag-pair must either not be there, or contain data.

The reason I want to do this is to suit the parsing script. Is it bad practise to validate an XML so specifically, for the benefit of the parsing algorithm, or is it okay to do that? - and if so, how do I specify that in the DTD?
brothercake is offline   Reply With Quote
Old 10-17-2002, 01:53 PM   PM User | #2
mpjbrennan
Regular Coder

 
Join Date: Jun 2002
Location: Newcastle, England
Posts: 178
Thanks: 0
Thanked 0 Times in 0 Posts
mpjbrennan is an unknown quantity at this point
I ws under the impression that if you specify an element contains PCDATA then it cannot be empty and still be valid.

patrick

No - I'm wrong!

Last edited by mpjbrennan; 10-17-2002 at 05:32 PM..
mpjbrennan is offline   Reply With Quote
Old 10-19-2002, 01:59 AM   PM User | #3
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,427
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
You can require the element have a child element. But that's about the best you'll be able to do in the DTD.

XML Schemas are much more defining and more strict, but they are incredibly complex.

If the XML document is in a Gecko-based browser like Netscape 6+ or Mozilla 1.0+, you can use a JavaScript with it:

<script xmlns="http://www.w3.org/1999/xhtml" src="myscript.js" />

-- and do your validation from there.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary
https://alexvincent.us/blog
Alex Vincent is offline   Reply With Quote
Old 10-19-2002, 08:17 AM   PM User | #4
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Quote:
Originally posted by Alex Vincent
you can use a JavaScript with it -- and do your validation from there.
You mean use the script to walk through the DOM and validate it like that? I hadn't thought of that ...

... but, i'm not DOM parsing it anyway. I'm doing it on the server using PHP extensions. It doesn't really validate; it just throws errors for malformed documents.

I remember reading a mention of Schema at w3schools; I think I'll check that out.

Thanks
brothercake is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:03 PM.


Advertisement
Log in to turn off these ads.