p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   XML (http://p2p.wrox.com/xml-91/)
-   -   Elements (EMPTY) and Attributes #Required (http://p2p.wrox.com/xml/5098-elements-empty-attributes-required.html)

Ian ORourke October 17th, 2003 06:07 AM

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?

pgtips October 17th, 2003 06:23 AM

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>

Ian ORourke October 17th, 2003 06:28 AM

My lack of experience on this is showing through, here is the DTD entry:

<!ATTLIST ship
    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)

joefawcett October 17th, 2003 06:36 AM

As pgtips said this means your element cannot contain other nodes:

<ship code="myCode" voyage="myVoyage"/>
Both attributes are required, these are illegal:

<ship code="myCode" voyage="myVoyage">Text</ship>
<ship voyage="myVoyage"/>
<ship code="myCode"/>



Ian ORourke October 17th, 2003 06:45 AM

Okay, I'm sure my Wrox books suggests an EMPTY assignment means I can have


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.

Ian ORourke October 17th, 2003 06:53 AM

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?

joefawcett October 17th, 2003 07:14 AM



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

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)

Ian ORourke October 17th, 2003 07:19 AM

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.

joefawcett October 17th, 2003 07:22 AM


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:


Joe (MVP - xml)

Ian ORourke October 17th, 2003 07:27 AM

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.

All times are GMT -4. The time now is 04:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.