 |
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
|
|
|

October 17th, 2003, 06:07 AM
|
Registered User
|
|
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Elements (EMPTY) and Attributes #Required
Okay we have a DTD sent to us by a business partner, and we are pretty new to this, and something has stumped us (and my Wrox books are not providing the miracle answer for once).
They have an Element with no marked as EMPTY but in the Element they have Attributes marked #REQUIRED.
How does that work as EMPTY means the element can be empty, but how can it be empty if it has #REQUIRED Attributes? Or is there some strange rule that comes into play when this combo is in a DTD?
|

October 17th, 2003, 06:23 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
empty just refers to the content between the open and close tags, not the attributes, so this would be allowed:
<theElement attr1="..."/>
but this would not
<theElement attr1="...">anything</theElement>
|

October 17th, 2003, 06:28 AM
|
Registered User
|
|
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
My lack of experience on this is showing through, here is the DTD entry:
<!ELEMENT ship EMPTY>
<!ATTLIST ship
code CDATA #REQUIRED
voyage CDATA #REQUIRED
>
Okay, so I assume from the above that I would HAVE to have a value for both code and and voyage?
Obviously the EMPTY means I can get away with something, but I'm not sure what the significance is of what I can omit? And what the difference is in including - as the data is not in the tags (and I have to include the data as they are #REQUIRED)
|

October 17th, 2003, 06:36 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
As pgtips said this means your element cannot contain other nodes:
Code:
<ship code="myCode" voyage="myVoyage"/>
Both attributes are required, these are illegal:
Code:
<ship code="myCode" voyage="myVoyage">Text</ship>
<ship voyage="myVoyage"/>
<ship code="myCode"/>
--
Joe
|

October 17th, 2003, 06:45 AM
|
Registered User
|
|
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Okay, I'm sure my Wrox books suggests an EMPTY assignment means I can have
<ship></ship>
But I'm sure your correct and I'm mis-reading it. The confusion I have is I have no concept of what these 'nodes' are within the tags?
I'll look into it now and educate myself, but any explanations you feel like adding would be greatly appreciated.
|

October 17th, 2003, 06:53 AM
|
Registered User
|
|
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So the Element itself can be given a value? Between it's tags...mmmm, I see. And Empty means it does not have one?
What are the assignments in the angled brackets for the Element? For example:
<ship code="myCode" voyage="myVoyage">Text</ship>
What is ship code="myCode" doing?
|

October 17th, 2003, 07:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
and
are equivalent in xml.
As for what your attributes code and voyage mean I have no idea...
Your DTD said the ship element has two required attributes, code and voyage.
You cannot have
because then ship would not be empty (it contains a text node), nor can you have
Code:
<ship><passengers/></ship>
it contains an element node.
If you are struggling with the terminology I suggest one of the seemingly infinite number of tutorials on the web.
Joe (MVP - xml)
|

October 17th, 2003, 07:19 AM
|
Registered User
|
|
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah, I'm pulling together some material now.
I just did not realise you could have 'something=something' within the angled brackets.
But time will reveal all :)
Thanks for your help, it has solved the immediate confusion.
|

October 17th, 2003, 07:22 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Quote:
quote:Originally posted by Ian ORourke
I just did not realise you could have 'something=something' within the angled brackets.
|
That something is an attribute, the angled brackets indicate elements, both elements and attributes are nodes.
This sample chapter looks quite good:
http://www.oreilly.com/catalog/learn...apter/ch02.pdf
Joe (MVP - xml)
|

October 17th, 2003, 07:27 AM
|
Registered User
|
|
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks. I have the Wrox 'Beginning XML 2nd Edition' book, but I read it like 6 months ago and then the XML died down. I'm cracking open the pages again.
|
|
 |