Is this valid XML?

Started by
16 comments, last by Antheus 12 years, 7 months ago
I know you can have:

<name>Sam</name>

and

<name>
<nickname>Wooty</nickname>
<nickname>Yogi</nickname>
<nickname>Chi-Lite</nickname>
</name>

but is this valid/legal:

<name>Sam
<nickname>Wooty</nickname>
<nickname>Yogi</nickname>
<nickname>Chi-Lite</nickname>
</name>

Beginner in Game Development?  Read here. And read here.

 

Advertisement
Well the W3C validator accepts it as long as you give slap a version tag on it first.
yes ... xml allows mixed content definitions for tags ... like this valid xhtml snippet

<div>And once he finally laid hands on <a href="daggers_of_ice.html">it</a> he felt a nearly irresistible compulsion to flee.</div>

it just isn't very desirable to do these types of formats when the focus is on data modelling / interchange vs markup.
Just out of curiosity, what exactly are you doing with said XML?

(Just remember... XML is like violence. If it doesn't work, you just aren't using enough of it...)
Well really this is for a FSM I'm working on.

Basically I wanted it to look like this:

<state>
<name>Assign Responsible</name>
<transition>Notify Responsible
<trigger_value>Open</trigger_value>
<trigger_value>Need Acknownledgement</trigger_value>
</transition>
<action>email</email>
</state>


Where name = state of current state, transition = name of the next state to move to, trigger_value = values needed to move to next state, action = any additional activity that must be performed while in current state.

Beginner in Game Development?  Read here. And read here.

 

Personally, I'd go for something like this:

<transition target="Notify Responsible">
<trigger_value>Open</trigger_value>
<trigger_value>Need Acknownledgement</trigger_value>
</transition>

<transition>
<target>Notify Responsible</target>
<trigger_value>Open</trigger_value>
<trigger_value>Need Acknowledgement</trigger_value>
</transition>


Is this more "acceptable" or is the difference between yours and mine a stylistic one?

Beginner in Game Development?  Read here. And read here.

 

Parsing blended CDATA and tags is a bit cumbersome in most libraries I've used, if that weighs into your decision any.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]



<transition>
<target>Notify Responsible</target>
<trigger_value>Open</trigger_value>
<trigger_value>Need Acknowledgement</trigger_value>
</transition>


Is this more "acceptable" or is the difference between yours and mine a stylistic one?

There's no real difference. For short, single, simple types an attribute is valid, for child nodes, long values or multiple values of the same type, sub nodes are preferable. What are your design goals ? Manual edited xml files, error robust files, easy to read, fast to read, small memory footprints ?

One tip: consider to use xml schema from the beginning to make your xml files schema conform and get some automatically xml file validation.

Parsing blended CDATA and tags is a bit cumbersome in most libraries I've used, if that weighs into your decision any.

I'm a beginner when it comes to XML. So though I've seen CDATA tags before, they won't be showing up in this XML... ever.

Beginner in Game Development?  Read here. And read here.

 

This topic is closed to new replies.

Advertisement