Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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
 
Old October 17th, 2003, 06:07 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

 
Old October 17th, 2003, 06:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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>
 
Old October 17th, 2003, 06:28 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)

 
Old October 17th, 2003, 06:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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
 
Old October 17th, 2003, 06:45 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 17th, 2003, 06:53 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old October 17th, 2003, 07:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
<ship/>
and
Code:
<ship></ship>
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
Code:
<ship>Text</ship>
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)
 
Old October 17th, 2003, 07:19 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 17th, 2003, 07:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old October 17th, 2003, 07:27 AM
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using xml elements as html attributes chipmaster XSLT 4 June 26th, 2007 10:22 AM
remove empty elements but not ones with attributes dupdup XSLT 1 March 3rd, 2007 07:02 PM
sequenced elements to attributes zkent XSLT 0 April 19th, 2006 08:50 AM
Elements and attributes Morrislgn XSLT 1 June 20th, 2005 11:13 AM
Elements w same name and their attributes supafly XSLT 1 May 30th, 2005 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.