An alternate approach to processing XML

Discussions

XML & Web services: An alternate approach to processing XML

  1. An alternate approach to processing XML (1 messages)

    I have been using an alternate approach to process XML that I thought others might find useful as well. Basically, it uses SAX to process a document into a key/value list that I call a Flat DOM. For example, a document like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <content xmlns="http:XMLSerialization">
    <object id="2">
    <class flag="3" id="0" name="NSArray" suid="-3789592578296478260">
    <field name="objects" type="java.lang.Object[]"/>
    </class>
    <array field="objects" id="4" ignoreEDB="1" length="3" type="java.lang.Object[]">
    <string id="5">The Chestry Oak</string>
    <string id="6">A Tree for Peter</string>
    <string id="7">The White Stag</string>
    </array>
    </object>
    </content>
    is converted into a list of key/value pairs like:

    /content/: #START#
    /content/@xmlns: http:XMLSerialization
    /content/object/: #START#
    /content/object/@id: 2
    /content/object/class/: #START#
    /content/object/class/@flag: 3
    /content/object/class/@id: 0
    /content/object/class/@name: NSArray
    /content/object/class/@suid: -3789592578296478260
    /content/object/class/field/: #START#
    /content/object/class/field/@name: objects
    /content/object/class/field/@type: java.lang.Object[]
    /content/object/class/field/: #END#
    /content/object/class/: #END#
    /content/object/array/: #START#
    /content/object/array/@field: objects
    /content/object/array/@id: 4
    /content/object/array/@ignoreEDB: 1
    /content/object/array/@length: 3
    /content/object/array/@type: java.lang.Object[]
    /content/object/array/string/: #START#
    /content/object/array/string/@id: 5
    /content/object/array/string/#text: The Chestry Oak
    /content/object/array/string/: #END#
    /content/object/array/string/: #START#
    /content/object/array/string/@id: 6
    /content/object/array/string/#text: A Tree for Peter
    /content/object/array/string/: #END#
    /content/object/array/string/: #START#
    /content/object/array/string/@id: 7
    /content/object/array/string/#text: The White Stag
    /content/object/array/string/: #END#
    /content/object/array/: #END#
    /content/object/: #END#
    /content/: #END#

    Iterating through this list and extracting the data you want is now relatively trivial. Creating this structure is extremely fast, and the structure itself is light.

    I have also written code to compress this structure and a version to handle HTML.

    If anyone is interested they can read the article and download the code.
  2. Sorry, I meant to post a direct link
    http://simple-software.ca/flat_dom.jsp