XML

First note on XML, more is needed.

Some definitions:

XML
eXtensible Markup Language
DTD
Document Type Definition. This describes the tags that can be used in a XML documents
XSD
XML Schema Definition

Basic rules

  • XML documents start with a XML-declaration. Specifying the xml version used.
    <?xml version=”1.0″ standalone=”no” encoding=”UTF-8″?>
    Standalone
  • The entire document is inside tags
  • Tags are in lowercase
  • All tags must be closed like <tagname>content</tagname> or <tagname   />
  • Tags must be correctly nested
  • All attribute values must be quoted (” or ‘)

Links:

  • http://www.w3.org/XML/
  • http://www.xml.com/
  • http://www.xml.org/
  • http://xml.coverpages.org/xml.html
  • http://www.ofx.net (attempt to put banking information in XML)

How an XML document looks

<?xml version=”1.0″ standalone=”no” encoding=”UTF-8″?> XML declaration, defines the version of XML used
<!DOCTYPE typename SYSTEM “typename.dtd”> Decalration of documenttype, define which dtd is to be used for this document.

DTD

How a DTD document looks

<!- comments -> Comments, for better understanding an readability .
<!ENTITY entityname “Entity content”> Entities can be called as &entityname; For content you can use ‘SYSTEM “URI”‘ to point to a local file, ‘PUBLIC “URI” points to an external resource.
<!ELEMENT elementname (subelement1, subelement2)> Define a tag and what can be inside it
<!ELEMENT elementname (#PCDATA)> Define a tag holding ‘parser controlled’ data (ascii)
<!ELEMENT elementname (subelement1*)> Define a tag that can hold subelement 0 or more times (use + for one or more, ? for one or zero,
<!ELEMENT elementname <(subelement1 | #PCDATA)*>> Define a tag that can hold subelement1 or PCDATA, the * at the end is mandatory for mixed data.
<!ATTLIST elementname attributename type option “value”> Define an attribute for elementname  see below for types and options.

Attribute types can be one of

  • CDATA, character data (ascii)
  • “value1″|”value2″|”value3”, Enumerated, a limited choice of values
  • IDREF and IDREFS,
  • ENTITY and ENTITIES,
  • NMTOKEN and NMTOKENS,
  • NOTATION, use data from a notation-declaration in the DTD

Attribute options can be one of

  • #REQUIRED, mandatory attribute.
  • #IMPLIED, optional attribute, no default value
  • #FIXED “value”, the attribute is optional, if it is there it will have “value”
  • text, the default value for the attribute

XSD

XSDs are another, more flexible way to define what a XML-document will look like. W3C used dtd’s for all there recommendations.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.