ietf-mxcomp
[Top] [All Lists]

Why XML

2004-06-22 08:38:25

All,

        I think that people need to see some examples of modern programming
that XML supports, these examples are in C#, but the metadata extensions in
the latest version of Java allow the same effect to be achieved:

        static XmlSerializer                    keyInfoReader;

        // Construct the serializer class from KeyInfoType
        keyInfoReader = new XmlSerializer (typeof (KeyInfoType));

        // Parse a KeyInfoType structure using the generated parser
        KeyInfoType keyInfoData = (KeyInfoType) keyInfoReader.Deserialize
(stringStream);


What is going on here is that XmlSerializer is reading the metadata that
defines the KeyInfoType structure, generating code to parse that structure,
and running it through the parser to generate the class.

This could be done at compile time since the methods are all static.


The KeyInfoType class is annotated with metadata as follows:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.w3.org/2000
/09/xmldsig#")]
[System.Xml.Serialization.XmlRootAttribute("KeyInfo",
Namespace="http://www.w3.org/2000/09/xmldsig#";, IsNullable=false)]
public class KeyInfoType {
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("KeyName",
typeof(string))]
        public string [] KeyName;

    [System.Xml.Serialization.XmlElementAttribute("KeyValue",
typeof(KeyValueType))]
        public KeyValueType [] KeyValue;

    ...
    }

This is considerably more verbose than it need be as this code was actually
generated directly from the schema using another tool.


A change to the schema can be accomodated without the need to change any of
the support code. I use the same code to parse XML data structures, save
them to disk etc in about six different programs.

This is not a new trick of course. People have done the same thing in LISP
for years, but that is not quite so interesting as there is only one data
structure in LISP.


The point is that you can only do this sort of thing if you have a regular
syntax for the data structure. ASN.1 and XML are regular enough to make this
possible.

I cannot write an SpfSerializer class, nor can anyone else. The rules for
parsing new data structures are unknowable.


The use of metadata is not an obscure programming idiom, it is the standard
way to code in the modern programming frameworks.

Writing flat code, without making use of metadata is in comparison like
writing code in assembly language. Sure I can do it, I used to write video
games in Z80 and 6502 assembler back in high school. But I would not write
an MUA in assembler and these days I would not write any sort of code
without metadata capabilities.

The angle bracket stuff is completely irrelevant as far as I and most other
XML coders are concerned. It is like x86 assembly code, I know it is there
but I don't want to see it.


                Phill


<Prev in Thread] Current Thread [Next in Thread>