Jump to content

  • Log In with Google      Sign In   
  • Create Account

Is this valid XML?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 14 September 2011 - 02:40 PM

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.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9670

Like
2Likes
Like

Posted 14 September 2011 - 02:54 PM

Well the W3C validator accepts it as long as you give slap a version tag on it first.

#3 Xai   Crossbones+   -  Reputation: 1459

Like
1Likes
Like

Posted 14 September 2011 - 02:59 PM

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.

#4 Moe   Crossbones+   -  Reputation: 1249

Like
2Likes
Like

Posted 14 September 2011 - 03:14 PM

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...)

#5 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 14 September 2011 - 03:33 PM

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.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#6 dmatter   Crossbones+   -  Reputation: 3298

Like
1Likes
Like

Posted 14 September 2011 - 04:21 PM

Personally, I'd go for something like this:
<transition target="Notify Responsible">
	<trigger_value>Open</trigger_value>
	<trigger_value>Need Acknownledgement</trigger_value>
</transition>


#7 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 14 September 2011 - 06:54 PM

<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.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#8 ApochPiQ   Moderators   -  Reputation: 16401

Like
0Likes
Like

Posted 14 September 2011 - 09:01 PM

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

#9 Ashaman73   Crossbones+   -  Reputation: 7991

Like
0Likes
Like

Posted 15 September 2011 - 12:05 AM

<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.

#10 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 15 September 2011 - 07:00 AM

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.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#11 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 15 September 2011 - 07:03 AM


<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.

This is a file that I would like to be (or can be): manually editable, easy to read, fast to read (for a human), and easy to XPath.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#12 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 15 September 2011 - 08:02 AM

It's well-formed. If there is only one root element. The above snippets are well-formed.

Valid XML requires a schema.

XPath

Needs a schema.

#13 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 15 September 2011 - 01:50 PM

.NET must be very lax then. Because I did XPath on XML that I wrote and it didn't scream at me.

Though, I'm pretty sure that I missed your point.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#14 Net Gnome   Members   -  Reputation: 773

Like
-1Likes
Like

Posted 15 September 2011 - 01:54 PM

Goto W3Schools, they have alot on XML and other related tech. Simple straightforward examples. Great place to learn the basics.

http://www.w3schools.com/

#15 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 15 September 2011 - 02:15 PM

.NET must be very lax then. Because I did XPath on XML that I wrote and it didn't scream at me.

Though, I'm pretty sure that I missed your point.


So few ever write valid XML that any real world parser needs to ignore validity and work with what it's got. Ideally, tools would reject all non-valid XML, but considering there were competing specs and standards, many of them pushed by heavyweights like IBM and Oracle, neither would cede and result in multiple exclusive yet standard-compliant and incompatible XML documents. People in the trenches got yelled when enterprise_big_arcane_soap_rfc service suddenly couldn't talk to another_enterprise_soap_provider and rigged them together into enterprise_grade_service_that_works_for_us_and_keeps_management_happy. Of course, when such company sold, there were now 3 incompatible XML providers...

This led to XML ecosystem being a complete mess and is generally being abandoned in favor of JSON by anyone who can do so.

XML makes sense if it's completely and correctly implemented. Otherwise it's just an unreadable tag soup, which is why it's universally hated, despite generally being a "Good Idea".

Similar idea. Ask any seasoned veteran and they'll agree it's a good idea, but the result in practice is just a useless mess that everyone abandoned.


IMHO - either implement XML fully and correctly so it passes all validations, including DTDs, published namespace and schema
or - use JSON.

JSON supports schemas or something similar, but parsers are allowed to be lax in what they accept. It does lack in the tooling department, but is not verbose, so complex tools aren't needed and grep gets you far.

#16 jbadams   Senior Staff   -  Reputation: 19374

Like
0Likes
Like

Posted 16 September 2011 - 02:35 AM

Goto W3Schools, they have alot on XML and other related tech. Simple straightforward examples. Great place to learn the basics.

Be careful about using W3Schools as a learning resource or reference, as there are a lot of problems with the information presented -- see "W3Fools" for further information. W3Schools can still be useful, but do take anything you read there with a grain of salt and be sure to check other sources.




#17 dmatter   Crossbones+   -  Reputation: 3298

Like
0Likes
Like

Posted 17 September 2011 - 07:28 AM

<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?

It's not really any more or less acceptable, just stylistic.


I might just stretch so far as to say that it's mine that may be more widely preferred, my intuition is that there are more guidelines out there something along the lines of:
Use an attribute over a nested element when:
* There's no more than 1 occurance permitted
* If it's mandatory
* When the content of the property is short and 'inline-able' like a number or a name.

The target property fits that description, but the trigger_value doesn't since you permit a variable number of them.

These are just ad-hoc rules though, it doesn't really make much difference. Some schemas allow you to specify a value either as an attribute or as a sub-element which allows the author to decide which is better.

#18 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 17 September 2011 - 08:06 AM

Be careful about using W3Schools as a learning resource or reference, as there are a lot of problems with the information presented -- see "W3Fools" for further information. W3Schools can still be useful, but do take anything you read there with a grain of salt and be sure to check other sources.


While they do point out a few issues, advice which lists: "Professional web developers do not recommend the use of WYSIWYG editors. " should be taken with a grain of salt as well.

The same crowd would scoff at anyone who ever in their career used anything but emacs or vi. The comments are way too similar to Ruby hipster crowd for my liking.

It reminds of various edge cases in C++. They make for endless debates, but are ultimately useless, because beginners will get stuck at linker error and MSVCRT redistributable problem.

Also, XML sections are not touched by W3Fools, since cool people don't touch XML. Which by default excludes anything even remotely related to any serious business or enterprise. If your font doesn't downgrade properly on IE8.1b2 nobody cares, but if your SOAPs are incompatible the servers will clog up and all your customers won't be able to pay. So, priorities...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS