Saturday 17 December 2011

What is XML well-formedness and how could you measure it?

XML well-formedness means that a document follows proper XML syntax. If not, the XML parser will spot lapses in the syntax of an XML document, stop processing the document and report them. So only well-formed documents are passed on to the application.

A well formed XML documents must satisfy a list of syntax rules. Key points of syntax rules are:
  • XML documents must have at least one element
  • XML documents must have a root element which has a unique opening and closing tag that contains all other elements
    <root>
      <child>
        <subchild>.....</subchild>
      </child>
    </root>
  • All elements must have a closing tag and they must be properly nested.
    <b><i>This text is bold and italic</i></b>
  • XML is case sensitive
    These are all legal names but they are all different names: chapter, Chapter, CHAPTER, ChApTer, chapteR
  • All attribute values must be quoted
    <file type="gif">computer.gif</file>
  • All names used must be well formed
    The first character must be a letter A-Z or a-z or a colon or an underscore. Numbers can not be used. A name can not be started with the group of 3 letters xml or XML or Xml etc.Other characters in the name can be those already mentioned, plus numbers 0-9, hyphens and fullstops.
Errors in XML documents will stop XML applications. The W3C XML specification states that a program should stop processing an XML document if it finds an error. The reason is that XML software should be small, fast, and compatible.With XML, errors are not allowed. To help syntax-check XML, W3C has created an XML validator.

No comments:

Post a Comment