Is this valid XML?

Started by
16 comments, last by Antheus 12 years, 7 months ago

[quote name='Alpha_ProgDes' timestamp='1316048061' post='4861823']

<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.
[/quote]
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. And read here.

 

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

Valid XML requires a schema.

XPath[/quote]
Needs a schema.
.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. And read here.

 

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

http://www.w3schools.com/

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

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.


- Jason Astle-Adams



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

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

This topic is closed to new replies.

Advertisement