Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 17th, 2003, 06:07 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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?

Reply With Quote
  #2 (permalink)  
Old October 17th, 2003, 06:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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>
Reply With Quote
  #3 (permalink)  
Old October 17th, 2003, 06:28 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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)

Reply With Quote
  #4 (permalink)  
Old October 17th, 2003, 06:36 AM
joefawcett's Avatar
Wrox Author
Points: 9,759, Level: 42
Points: 9,759, Level: 42 Points: 9,759, Level: 42 Points: 9,759, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,073
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
Reply With Quote
  #5 (permalink)  
Old October 17th, 2003, 06:45 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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.

Reply With Quote
  #6 (permalink)  
Old October 17th, 2003, 06:53 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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?

Reply With Quote
  #7 (permalink)  
Old October 17th, 2003, 07:14 AM
joefawcett's Avatar
Wrox Author
Points: 9,759, Level: 42
Points: 9,759, Level: 42 Points: 9,759, Level: 42 Points: 9,759, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,073
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)
Reply With Quote
  #8 (permalink)  
Old October 17th, 2003, 07:19 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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.

Reply With Quote
  #9 (permalink)  
Old October 17th, 2003, 07:22 AM
joefawcett's Avatar
Wrox Author
Points: 9,759, Level: 42
Points: 9,759, Level: 42 Points: 9,759, Level: 42 Points: 9,759, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,073
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)
Reply With Quote
  #10 (permalink)  
Old October 17th, 2003, 07:27 AM
Registered User
 
Join Date: Oct 2003
Location: , , .
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.

Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 08:25 PM.


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