20 March 2012

XML list elements, Sclerotic Internet

XML list elements, Sclerotic Internet

I hate XML almost as much as I hate ASN.1

To merely list elements, without knowing names in advance, which would surely defeat the purpose, you need xalan.jar
and the rather neat xpath concept

You cant use java javax.xml
you need org.apache.xpath.XPathAPI.
You need to download the entire 65MB of xalan just to get xalan.jar

Sadly, such sites as jarfinder and findjar now just point to ad-sites which dont actually find jars

After an afternoon searching for XML stuff on the Internet, I find it sclerotic, clogged with undated pages offering obsolete or deprecated methods
Without a means to die, evolution is impossible, and we are left with Stalinist relics pretending to function.


Anyway to converts an XML document into a comma separated list.
Comma separated is so much simpler, ergo better...




        NodeList nodelist = null;
        String xpath = "//*[not(*)]"; // Get all elements without a child element




        nodelist = org.apache.xpath.XPathAPI.selectNodeList(doc, xpath);\
        int z = nodelist.getLength();

        for (int i=0; i < z ; i++) { print("\n " + postColon(nodelist.item(i).getNodeName())); // postcolon removes the ds: and dct: - what possible use are they?
        print(", " + nodelist.item(i).getTextContent());
         }


 note the .item(i) syntax - this varies from xalan to Java - making a mockery of the idea of XML as a standard... exampledepot - lots of neat strings to select

No comments:

Post a Comment