# xml 'logic': text or attribute?

## Recommended Posts

Currently I'm working on something with XML and I'm in doubt of some minor issue: when to include some information as an atribute of an element and when to include it as the text. Maybe I'm nitpicking, but I'd like this to be logical and consistent, so do you have any opinion, advice or good rule of the thumb for me? For example:
<Image name="SomeTexture" id="3" format="png" w="256", h="256">
<Offset x="6" y="30" />
</Image>

or:
<Image id="3" format="png" w="256", h="256">
SomeTexture
<Offset x="6" y="30" />
</Image>

I seem inclined to think of everything as an attribute, except for strings (as resources, like dialog text) which are the real thing.

##### Share on other sites
I use it as an attribute, mainly because text in my opinion is to be used for stories and dialog.

I use the FreeImage library so I don't really care how big, and what format the images are. If there are sprites that need these images, their texture UVs are calculated once at runtime.

<?xml version="1.0" encoding="ISO-8859-1"?><game><resources>	<texturelist>		<texture name="game" file="images/game.png"/>	</texturelist>	<spritelist>		<sprite name="scene" textureName="game">			<animation name="floor1" width="1024" height="200">				<quad x1="0" y1="0" x2="1023" y2="199"/>			</animation>		</sprite>		<sprite name="player" textureName="game">			<animation name="walk" width="40" height="70">				<quad x1="1088" y1="0" x2="1127" y2="69"/>				<quad x1="1128" y1="0" x2="1167" y2="69"/>				<quad x1="1168" y1="0" x2="1207" y2="69"/>				<quad x1="1208" y1="0" x2="1247" y2="69"/>			</animation>		</sprite>		<sprite name="test" textureName="game">			<animation name="test" width="500" height="100">				<quad x1="0" y1="0" x2="1024" y2="1024"/>			</animation>		</sprite>	</spritelist>	<fontlist>		<font name="default" fontface="Verdana" size="10"/>	</fontlist>	<soundlist>		<sound name="sound" file="sound.wav"/>	</soundlist></resources></game>

##### Share on other sites
Descriptions and comments are what I use text for. Generally, object properties are in a name = value format. So, to answer your question, your first example would be more suitable IMHO.

##### Share on other sites
Well thanks that certainly fits with my intuition, PumpkinPieman's example is the kind of consistency I was looking for. I don't know why I got this weird idea in my head that somehow this 'text' thing must be used for something other than 'string resources'.

(btw I'm making some sort of little app for batching image operations, like conversion and creating tightly packed spritesheets. Format, width and height can be useful for that, that's why)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978704

• 21
• 14
• 12
• 10
• 12