Eric Smith
Usenet Archive
- Joined
- Jan 28, 2000
- Messages
- 203
- Reaction score
- 0
I'm writing a DTD for a simulator to save the state of the simulated machine, such as register and memory contents. In this particular application, it is not expected that the generated XML will normally be seen or edited by a person, either as text or in a structured XML editor. It is only intended as an intermediate storage format, so that the same state can be loaded back into the simulator at a later time.
My first thought was to use an element for a memory location, with an attribute for the address, and text contents of the element for the data:
<loc addr="12a7">4e</loc>
Then it occurred to me to try using attributes only:
<loc addr="12a7" data="4e"/>
When I started actually writing the DTD, I saw a web page advising that attributes not be used for significant data. The given reason was that attributes are harder to parse. I'm using a SAX-based parser, and find that attributes are actually quite easy to deal with. So is there any good reason to avoid the two styles above? It seems like the alternative would be very cumbersome:
<loc><addr>12a7</addr><data>4e</data></loc>
And that would in fact take more work to process with SAX. By using attributes only (my second example above), I can write the DTD to simply require both the addr and data attributes, and not have to maintain as much state in my own parser code.
I think what I'm mostly asking is whether the attribute-only model is really considered to be poor form, and if so, how poor, and for what reasons? Would using it cause problems that would haunt me later?
Thanks for any advice or insights.
Eric
My first thought was to use an element for a memory location, with an attribute for the address, and text contents of the element for the data:
<loc addr="12a7">4e</loc>
Then it occurred to me to try using attributes only:
<loc addr="12a7" data="4e"/>
When I started actually writing the DTD, I saw a web page advising that attributes not be used for significant data. The given reason was that attributes are harder to parse. I'm using a SAX-based parser, and find that attributes are actually quite easy to deal with. So is there any good reason to avoid the two styles above? It seems like the alternative would be very cumbersome:
<loc><addr>12a7</addr><data>4e</data></loc>
And that would in fact take more work to process with SAX. By using attributes only (my second example above), I can write the DTD to simply require both the addr and data attributes, and not have to maintain as much state in my own parser code.
I think what I'm mostly asking is whether the attribute-only model is really considered to be poor form, and if so, how poor, and for what reasons? Would using it cause problems that would haunt me later?
Thanks for any advice or insights.
Eric