Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Wednesday, June 3, 2009

XML Infoset Models

The XML Information Set (Infoset) defines a number of classes that can be used to model XML documents, and to some extent, this is exactly the model used in other W3C specifications. However, some specifications use less or more than this set of classes, and it is insightful to compare them in order to find common subsets, and exhaustive supersets. In the comparison below "Info" means XML Infoset and "Path" means the XPath/XQuery Data Model. Also, the abbreviations (Y = yes/required, N = no/unspecified, O = optional) are used.

Class Name XMLDOMEXIInfoPath
AttributeYYYYY
CDATASection YYNNN
CharacterData YYYYN
Comment YYOYY
DocumentYYYYY
DocumentFragment NYYNN
DocumentType YOOYN
ElementYYYYY
Entity YOOYN
EntityReference YOOYN
NamespaceYOOYY
Notation YONYN
ProcessingInstruction YOOYY
TextYYYYY

Technically, XML Infoset does not include a CharacterData class, but includes a Character class that can be made into a list, which would be isomorphic to the CharacterData class. DOM only requires the optional classes if hasFeature("XML", "1.0") is implemented, so for all XML DOM implementations, these are not optional. Also, EXI requires the Namespace class, even though preserving the namespace prefix strings is optional. XPath has the smallest model, which only supports 7 of the above classes.

It is also interesting to note that Comments, Namespaces and ProcessingInstructions are not forbidden by any of the standards considered above. Also, as you can see, the only classes required by all W3C models are: Attributes, Elements, Documents, Namespaces and Text. Why all the bloat?

Saturday, May 30, 2009

Nonstandard Namespaces

XML namespaces are inherently vendor-neutral, and as such, anyone can define one, even me. So in order to help standardize XML dialects that do not define a namespace, I have put together a list of document types that really should have a namespace, but have not taken the time to define one.

r6rs (Scheme R6RS)
http://www.r6rs.org/final/html/r6rs/r6rs.html
r5rs (Scheme R5RS)
http://www.schemers.org/Documents/Standards/R5RS/
cl (Common Lisp)
http://www.lispworks.com/documentation/HyperSpec/
cs (CS, CEL)
http://www.crystalspace3d.org/2000/cs_world
x3d (X3D, VRML)
http://www.web3d.org/specifications/x3d-namespace
pl (Apple PList)
http://www.apple.com/DTDs/PropertyList-1.0.dtd

There really isn't much to say about these. Some of them are based on resources which describe the XML dialects, whereas others (like x3d-namespace) are a version-neutral namespace (while some X3D implementors have used x3d-3.0.xsd or x3d-3.2.xsd, for which files actually exist). If anyone thinks some of these are poor choices, then let me know, and I'll change it.

Webizing Common Lisp

Lisp is a very old language, but it is by no means old in the derogatory sense. Being the oldest language (except Fortran) has given it time to mature and grow into a language capable of amazing things. It has been said many places that Lisp and XML are similar in that they are both data (and if you include XAML and XSLT, code too). I would argue, though, that Common Lisp has vastly more features. However, to make a true comparison, we have to webize Lisp. At the very least, this requires a URI for every symbol. We can start by giving a namespace to all symbols in the COMMON-LISP package.

http://www.lispworks.com/documentation/HyperSpec/

For convinience, we will use the cl prefix for this namespace. We can now start relating Web standards and Lisp, or even writing ontologies using Lisp functions.

Lets compare lists, which are a fundamental part of Lisp. In Lisp, a cons (x . y) would correspond to the RDF graph given by [ a rdf:List ; rdf:first _:x ; rdf:rest _:y ] and cl:nil would correspond to rdf:nil. We can do this with almost all Lisp syntax, except perhaps for the syntax based on the hash (#) symbol. For example, #c(3 4) would correspond to the MathML <cn type="complex-cartesian">3<sep/>4</cn>, so the mapping can get complicated.

Considering such a mapping between Lisp and XML has many advantages. One thing they both have in common is the idea of homogenous data, however, when viewed as two separate syntaxes, they are incompatible, because XML would be a string in Lisp, and Lisp would be a string in XML, losing all structure. When considering such a mapping, it may seem equally advantageous to express XML in Lisp, and conversely, Lisp in XML. If only it were a bijection...

Tuesday, April 28, 2009

XML - Entity References

When we go about writing a web page, often enough, we like using all sorts of characters in our text, like exclamation points (!), ampersands (&), and less than signs (<). Sooner or later, it becomes obvious that we need a way to put a character in our web pages without using the character itself. For example, the less than sign (<) is part of XML markup, so it cannot be used in the text itself, so to remedy this situation the entity reference &lt; is used. This expands to (<) when the page is viewed in a browser, so the desired effect is achieved.

The concept of XML entities was borrowed from SGML, and so their inner workings are very similar. Another borrowing from SGML is the DOCTYPE declaration. While backwards-compatibility was an important objective for XML 1.0, it is a low priority now that XML processors are ubiquitous, and rarely depend on more general SGML processing. In fact, now that XML Schema has replaced almost every aspect of the Document Type Declaration (DTD), it is likely that the use of DTDs will diminish. Since XML Schema provides a richer environment for declaring elements and defining types, it seems painful to have to use DTDs. This naturally leads to the question of whether or not DTDs can be removed from the XML specification.

Suppose DTDs were removed from the XML specification (perhaps for XML 1.5). What else would have to be changed in order to maintain consistency? Surprisingly, only entities. Everything else can be equivalently (or better) declared in XML Schema, which also provides rich types that can increase validity constraints where DTDs would not. However, XML Schema does not provide a way to define entities. So if a new mechanism for entity definition is required, then it could be one of the following options:

  • Use a simplified DOCTYPE declaration for compatibility.
  • Create a new processing instruction to include entities.
  • Let the user agent handle entities however it wants.

Of these options, the new processing instruction would be the most consistent with W3C's other specifications, such as Associating Style Sheets with XML documents. Also, it would be a chance to codify current best practice. XML allows entities to be defined internally (within the document) and externally (in another file). Most documents that use entities either depend on a standard list of entities (like HTML Entities) or directly include a file which has entity definitions. So while a hypothetical processing instruction <?xml-entity copy "&#169;"?> would do the job, it would go against everything. A hypothetical processing instruction <?xml-entities href="htmllat1.ent"?> would be more in line with current usage. Since this would introduce a new language for this external file, there would have to be at least two parts to a specification of this idea:

  • entSubset  ::= (GEDecl | Comment | S)*
  • EntitiesPI ::= '<?xml-entities' S PseudoAtt S? '?>'
    where the allowed pseudo-attributes are:
    href    CDATA #REQUIRED
    charset CDATA #IMPLIED

Another benefit of using a processing instruction instead of some other method is that you do not have to wait until a new XML processor is implemented. In the worst case scenario, you could pass the document through a tool that understands that processing instruction, and the rest can be handled by a normal XML processor. Thus, you can live in a DTD-free world without waiting for XML 1.5 ... you can have it your way, today.