PDA

View Full Version : Nodes vs attributes



Varsuuk
July 14th, 2023, 18:59
I have the weirdest block with XML at times, plus with my lifetime of sleep deprivation and ADHD... my memory on anything I don't do regularly - is <bleep>ed.
I suspect I have asked this afore.

Is there a rule of thumb when to use an attribute vs node? I suspect one pro of using an attribute is that it is lighter weight than nested nodes (though, I am as likely wrong ;P) and that nodes might be easier to partially replace when merging?

Like


<template...
<anchored>
<size>
<width>50</width>
</size>
<top parent="alignment_label" />
<bottom parent="alignment_label" />
<left parent="alignment" anchor="right" offset="20"/>
</anchored>
...
</template>


vs


<template...
<anchored width="59">
<top parent="alignment_label" />
<bottom parent="alignment_label" />
<left parent="alignment" anchor="right" offset="20"/>
</anchored>
...
</template>


or whatever?


If one wanted to just update in a derived template (or control instantiation) just the width - would both ones be as easily overidden or would the second (attrib) require rewriting the whole thing?

Moon Wizard
July 14th, 2023, 19:23
The attribute implementation is more compact, and I favor that approach.
The only time I use broken out tags is if I need to reference the XML from a script, which is very rare.

Regards,
JPG