Reputation: 27885
I would like to know if there are any xml coding standards.
<?xml version="1.0"?>
<overlay id="tutorboy-toolbar-Overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<toolbox id="navigator-toolbox">
<toolbar id="tutorboy-toolbar-Toolbar"
toolbarname="TutorBoy Toolbar"
accesskey="T"
class="chromeclass-toolbar"
context="toolbar-context-menu"
hidden="false"
persist="hidden">
<toolbarbutton label="TutorBoy"
id="tutorboy-toolbar-button-home"
accesskey="d"
image="chrome://tutorboy-toolbar/skin/logo.png"
oncommand="loadURL('http://tutorboy.com');"
tooltiptext="Click here to go to the Tutorboy.com homepage." />
is this way of arrangement allowed?
Upvotes: 11
Views: 15427
Reputation: 7678
http://en.wikipedia.org/wiki/XML
Look under "Well-formedness"
There aren't many standards since it is meant to be very flexible.
Upvotes: 2
Reputation: 11
as a general rule of thumb: Put data in separate elements and metadata in attributes.
Upvotes: 1
Reputation: 143925
I suggest you to take a look at XMLPatterns. You won't find "coding style" suggestions, but you will find interesting design patterns (a la GangOfFour) for XML document structure.
For "coding style", I would check examples and try to imitate them. When in doubt, try different strategies and find the one that is clear and appealing. My opinion about your example is positive. tag/attribute names can however be an issue: lowercase no spaced, lowercase underscore spaced, camel case, capitalized camel case?
Upvotes: 0
Reputation: 35529
There is one reference formatting, XML Canonical, which is implemented in tools like xmllint (option --c14n
). These tools can therefore be used as pretty-printers.
But of course you are not forced to use it. Like any formatting rules, it is a matter of taste. Just be consistent.
Upvotes: 4
Reputation: 6198
The W3C defines an XML specification recommendation: http://www.w3.org/TR/REC-xml/
Since you've narrowed your question to XML formatting, there's no "universal" answer to how your XML should be formatted. Beyond conforming to whatever DTD or schema you happen to be dealing with, the importance of particular spacing/indentation of your tags lies with the people who will be dealing with your data.
If you're creating XML data to be sent across a network as part of a web service or some sort, then generally you're going to want to eliminate any unnecessary whitespace before transfer in order to optimize your data transfer rate. This means no line breaks, no indentation, no comments.
If your creating an XML document that others will be reading/modifying on a regular basis, then obviously you'll want to put some consideration into keeping the document readable. What constitutes "readable" is determined by everyone involved on that particular team or project.
Upvotes: 16
Reputation: 3209
Well, I would suggest looking at
http://www.xfront.com/BestPracticesHomepage.html or the results of any google search under XML best practices.
I would say the standards include linking to an XSD file, proper escape characters ; etc etc
Upvotes: 4