KXML

From Makers Local 256
Revision as of 21:46, 6 July 2008 by Opticron (Talk | contribs)

Jump to: navigation, search

Creator:
Opticron
Status:
Late Development
Born On:
00:49, 22 June 2008 (CDT)
Last Updated:
{{{Last Updated}}}

Overview

This project tracks the development of the DOM XML parsing library written in D by User:Opticron. This project was born of the need for an XML parser where none existed that relied on Phobos, supported unparsed cdata nodes, and worked properly with D1.0. The parser operates on strings and attempts to allocate as little memory as possible by using slice references into the original string provided. The parser is loosely based on the Yage XML parser, also written in D. KXML has a completely new parsing engine, but attempts to remain mostly api-compatible with the Yage parser. The parser can currently deal with XML processing instructions, unparsed character data, standard, and self-closing nodes. It will ignore node types it doesn't understand. The code is on the Narrows SVN server under kxml.

Usage Examples

Create an XML element with the name "foo".

XmlNode foo = new XmlNode("foo");

Add an attribute with the name "bar" and value "foobar"

foo.setAttribute("bar","foobar");

Get the first child node of foo

XmlNode firstchild = foo.getChildren()[0];

Get the attribute named bar

char[]barval = foo.getAttribute("bar");

Parse a string for XML

foo = readDocument(xmlstring);

Quirks

  • Always outputs XML with double quoted attributes
  • The input string may not always be the same as the output string
    • Unparsed CData nodes will be escaped and left as regular CData

To Do

  • Increase Parsing Speed
    • Only iterate through the string once
  • Implement some kind of query mechanism that returns an array of nodes (i may just want to use real xpath syntax)
    • Search on node names (node1/node2/node3)
    • Search on attribute names (node1/node2/attribute)
    • Search on attribute values (node1/=value)
    • Search on name=value pairs (node1/node2/node3:attribute=value)
    • Search on multiple parameters (node1:toast=buttered/node2:dogs=hot/node3:firefox=memoryhog:cpu=slow)
  • Add an opIndex for child node access (integer)
  • Add an opIndex for attribute access (string)