• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting up a XML document

 
Matthew Roth
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, good info!
Especially the When should I use elements, when should I use attributes at oasis.
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic