Grouping of elements?

H

howa

The following show two examples, which one is better you think?

<report>
<minScore></minScore>
<maxScore></maxScore>

.... other stuffs
</report>

or

<report>
<score>
<maxScore></maxScore>
<minScore></minScore>
</score>
...
</report>
 
P

Peter Flynn

howa said:
The following show two examples, which one is better you think?

<report>
<minScore></minScore>
<maxScore></maxScore>

... other stuffs
</report>

or

<report>
<score>
<maxScore></maxScore>
<minScore></minScore>
</score>
...
</report>

If the scores are textual, then the redundancy is unnecessary:

<report>
<scores>
<min></min>
<max></max>
</scores>
....
</report>

If the scores are numeric or categorical, attributes are more common:

<report>
<score min="34" max="57"/>
....
</report>

///Peter
 
J

Joe Kesselman

As with other data structures, this depends on how you're going to use
the data now and in the future. If you will eventually be making "score"
more complicated, having it be a separate element may make sense. If min
and max score are really just part of the report, the extra level of
hierarchy may not make sense.

Why do you want the <score> element? If you can't explain that (to
yourself), you probably don't want it.
 
H

howa

Hello all,

One of my concern is: If I parse the XML into DOM, will attribute or
new element using more memory at runtime?
 
J

Joseph Kesselman

George said:
Elements will occupy more memory than attributes.

Probably, BUT the proper answer depends on ****EXACTLY**** which
implementation of the DOM you're using.

Remember that the DOM is only an interface, and very carefully leaves
the question of back-end storage open; the actual document storage model
may not be a DOM and may not even be object-based, which makes
generalizing about memory usage difficult.

If this matters to you, you may want to pick your implementation
specifically by how it manages storage.
 
H

howa

Maybe it will be better if

<report maxScore="34" maxScore="57">

....

?

Personally, I don't like empty element with attributes.

Or is it the common way to do in this way?

Thanks.
 
J

Joseph Kesselman

howa said:
<report maxScore="34" maxScore="57">

That would be my own inclination.
Personally, I don't like empty element with attributes.

As I said: The question is how much structure you think you might add in
the future. Attributes can't have XML substructure, so if things
eventually get more complicated you will have to either add more
attributes, more children, or a more complicated syntax for your
attribute values.

Very much a matter of taste and style. Do whatever makes most sense for
the markup language you're working with and the applications that will
manipulate it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top