3 ms·
Attributes are XML’s foot-gun.
by dbcurtis 7y ago
Attributes are XML’s foot-gun.
- papaf 7y agoAttributes are XML’s foot-gun. I disagree. Back in the day we used attributes for everything that was key value and inner tags for anything with structure. We also formatted for clarity: <lunch env="outside" food="sandwiches" drink="cola" /> Compared with what we used to do, I look at attribute-less maven pom.xml with horror.
- johnchristopher 7y agoWhat if it's to be used by french speaking software/people ? <lunch env="outside" envfr="dehors" food="sandwiches" foodfr="sandwichs" drink="cola" /> Or <lunch env="outside" food="sandwiches" drink="cola"> <label type="env" language="fr">Dehors</label> <label type="env" language="de">Außenseite</label> <label type="env" language="en">Outside</label> </lunch> Quite curious about it.
- snuxoll 7y agoPutting l10n/i18n data inline is generally not a pleasant experience, and this problem persists regardless of what serialization format you are using. Either have separate data files per-locale that are merged with the defaults or store the localized strings in a central location (ala your usual gettext setup).
- yosamino 7y agoI guess this way: <lunch env="outside" food="sandwiches" drink="cola"> <label xml:lang="fr">Dehors</label> <label xml:lang="de">Draußen</label> <label xml:lang="en">Outside</label> </lunch> says[0]the w3. [0]https://www.w3.org/TR/REC-xml/#sec-lang-tag https://www.w3.org/TR/REC-xml/#sec-lang-tag
- johnchristopher 7y agoI see, thanks. (I also see you corrected my broken German ^^).
- dbcurtis 7y agoThe decision of when and how to use attributes is the thing that is most often done wrong or clumsily in an XML file. That is my point.
- twic 7y agoParticularly annoying is that there's no way to do lists with attributes. Looks good: <user name="alice" group="wheel" /> Oh no: <user name="alice" groups="wheel admin sudoers" /> Or is it one of: <user name="alice" groups="wheel,admin,sudoers" /> <user name="alice" groups="wheel:admin:sudoers" /> <user name="alice" groups="wheel;admin;sudoers" /> Or give up and use elements: <user name="alice"> <group>wheel</group> <group>admin</group> <group>sudoers</group> </user> Hold on, should there be a container? <user name="alice"> <groups> <group>wheel</group> <group>admin</group> <group>sudoers</group> </groups> </user> XML really needs either richer attributes, or no attributes.
- Ooolin 7y agoReplace with "Element" with "Class" and "Attribute" with "Property" in your examples. It's your job to decide how the data should be structured, in any language. I would do the following : <user name="alice"> <groups> <group uid="wheel"/> <group uid="admin"/> <group uid="sudoers"/> </groups> </user>