include "xml.m";
xml := load Xml Xml->PATH;
Parser, Item, Location, Attributes, Mark: import xml;
init:   fn(): string;
open: fn(f: string, warning: chan of (Locator, string),
                preelem: string): (ref Parser, string);
fopen: fn(iob: ref Bufio->Iobuf, f: string, warning: chan of (Locator, string),
                preelem: string): (ref Parser, string);
Parser: adt {
    fileoffset: int;
    next:       fn(p: self ref Parser): ref Item;
    down:       fn(p: self ref Parser);
    up:         fn(p: self ref Parser);
    mark:       fn(p: self ref Parser): ref Mark;
    atmark:     fn(p: self ref Parser, m: ref Mark): int;
    goto:       fn(p: self ref Parser, m: ref Mark);
    str2mark:   fn(p: self ref Parser, s: string): ref Mark;
};
Item: adt {
    fileoffset: int;
    pick {
    Tag =>
        name:   string;
        attrs:  Attributes;
    Text =>
        ch:     string;
        ws1:	int;
		ws2:    int;
    Process =>
        target: string;
        data:   string;
    Doctype =>
        name:   string;
        public: int;
        params: list of string;
    Stylesheet =>
        attrs:  Attributes;
    Error =>
        loc:    Locator;
        msg:    string;
    }
};
Locator: adt {
    line:       int;
    systemid:   string;
    publicid:   string;
};
Attribute: adt {
    name:       string;
    value:      string;
};
Attributes: adt {
    all:        fn(a: self Attributes): list of Attribute;
    get:        fn(a: self Attributes, name: string): string;
};
Mark: adt {
    offset:     int;
    str:        fn(m: self ref Mark): string;   
};
Once an XML document has been opened, the following Parser methods may be used to examine the items contained within:
The attribute-value pairs in Tag and Stylesheet items are held in an Atttributes adt, say a. A.all() yields a list holding all the attributes; a.get(name) yields the value of the attribute name.
The location returned when an error is reported is held inside a Locator adt, which holds the line number on which the error occurred, the ``system id'' of the document (in this implementation, its file name), and the "public id" of the document (not currently used).
A Mark m may be converted to a string with m.str(); this enables marks to be written out to external storage, to index a large XML document, for example. Note that if the XML document changes, any stored marks will no longer be valid.
| XML(2 ) | Rev: Thu Feb 15 14:43:27 GMT 2007 |