aspose file tools*
The moose likes XML and Related Technologies and the fly likes Setting up a XML document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Setting up a XML document" Watch "Setting up a XML document" New topic
Author

Setting up a XML document

Matthew Roth
Greenhorn

Joined: Jan 30, 2001
Posts: 19
I'm new to xml and I need help on setting one up. Is it "good"
xmling to have
the elements empty and put all of the data in to the attributes?
I'm setting the xml up to hold a database table. Here is an example of both of my ideas:
<col name="year">1999</col>
<col name="year" data="1999"></col>
or is there a better way???
Thanks for your help. --Yulan
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Is it "good" xmling to have the elements empty and put all of the data in to the attributes?
That is too extreme approach, although it may work in some cases. But in general the answer really depend on nature of your data. Here is a table for �attributes vs. element� consideration:

if anybody can add something, please, do not hesitate

[This message has been edited by Mapraputa Is (edited April 19, 2001).]


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Elements Vs Attributes -

  • It is easier to edit/display Element content than Attribute values.
  • Processors can check Attribute values easily than Element content.
  • It is easier to extract information from attributes than from sub-elements.
  • Attributes can have default values, Elements cannot.
  • Elements define content, Attributes describe content

  • Attributes should be used to repersent "internal" data - something that is not the data itself, but describes the data( aka metadata ). IDs, cross-element references, record number etc are examples. Attributes are also used to describe the special qualifiers for the content that follows - eg., imageType = "GIF", or encoding = "UTF6251" etc.
    Contents should be used to store the actual data name, department, salary etc are examples.
    Also note that attribute based queries are not as flexible as content-based queries. Unlike elements, attributes are not considered as stand alone entities. You cannot represent hierarchical information using an attribute. These are other considerations in favour of using elements vs. attribute.

    Cheers!
    ------------------
    Ajith Kallambella M.
    Sun Certified Programmer for the Java�2 Platform.
    IBM Certified Developer - XML and Related Technologies, V1.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
To add extra 0.02$...
Attributes can be prefered over elements for compactness reasons:
<element someName=�123�/>
is more compact than
<element>
<someName>123</someName>
</element>
and if you have thousands of elements...
SVG designers ever went further and introduced this ugly syntax:
<path d="M 100 100 L 140 100 L 120 140 z"/>
- for the very compactness reason.
�A verbose XML syntax not only increases the size of a file, but also imposes additional memory overheads when constructing a DOM tree.�
(http://www.xml.com/pub/a/2000/03/15/deviant/index.html)
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1449
Map,
Did you develop your list 'o things to consider yourself or did you read this somewhere (or both)? Could you tell us the source(s)?
BTW, I notice that the list says that attributes can be validated to have enumerated values while elements can't. I thought the schemas allowed you to do that with elements. Am I misremembering or misinterpretting something?
John


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065

d�j�-vu
I remember I had problem with posting tables because HTML is turned off in this forum, so I FTPed "Attributes vs. Elements" table on our server. Here it is. I must have forgotten about this thread.
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1449
Ah, good info!
Especially the When should I use elements, when should I use attributes at oasis.
John
 
jQuery in Action, 2nd edition
 
subject: Setting up a XML document