views:

593

answers:

5

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"&gt;
    <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?

+2  A: 

http://en.wikipedia.org/wiki/XML

Look under "Well-formedness"

There aren't many standards since it is meant to be very flexible.

Sam
Specifically, the posted XML is not well-formed. The ones you'll be interested in are: there can only be one root-level element, and every tag that is not self-closing (does not end with /> ) must have a closing tag.
GalacticCowboy
+3  A: 

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

PSU_Kardi
+8  A: 

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.

Jeff L
Precisely. White space should be completely meaningless to the semantics, and its presence or absence is a matter of taste. And since XML is primarily *not* intended for human readability, formatting is of no particular concern.
GalacticCowboy
+1  A: 

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.

bortzmeyer
Actually this is kind of the formatting standard. IMHO this answers the question.
Boldewyn
A: 

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?

Stefano Borini