Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

55xml Module

The xml module provides measures to parse or compose XML documents.

There are two ways to parse an XML document as follows.

One is to create an xml.document instance from a stream that contains all the XML elements with a tree structure. This is an easy way to parse an XML document but consumes much memory. Below is an example to read an XML file test.xml:

doc = xml.document('test.xml')
// doc contains all the information of XML document

Another one is to create a class inherited xml.parser and implements event handlers that respond to tags, comments and texts, and then executes xml.parser#parse() method with it. Below is an example to create a class that implements a handler for StartElement event:

Parser = class(xml.parser) {
    StartElement(elem) = {
        printf('<%s>\n', elem.tagname)
    }
}
Parser().parse('test.xml')

55.1xml.attribute Class

The xml.attribute instance represents a name-value pair of XML's attribute that can be retrieved from attrs property in the xml.element instance.

55.1.1Property

Property Type R/W Explanation
name string R
value string R

55.2xml.document Class

55.2.1Constructor

xml.document
xml.document(stream?:stream:r) {block?}

55.2.2Property

Property Type R/W Explanation
version string R
encoding string R
root xml.element R

55.2.3Method

xml.document#parse
xml.document#parse(str:string):void

xml.document#read
xml.document#read(stream:stream:r):void

xml.document#textize
xml.document#textize(fancy?:boolean, tabs?:number)

xml.document#write
xml.document#write(stream:stream:w, fancy?:boolean, tabs?:number):void

55.3xml.element Class

55.3.1Constructor

xml.element
xml.element(_tagname_:string, attrs%):map {block?}

xml.comment
xml.comment(comment:string)

55.3.2Property

Property Type R/W Explanation
tagname string R A tag name of this element.
text string R The text string if the element is TEXT. Otherwise, this value would be nil.
comment string R The comment string if the element is COMMENT. Otherwise, this value would be nil.
children iterator R An iterator to return xml.element instances that represent children contained in this element. This value would be nil if the element has no children.
attrs iterator R An iterator to return xml.attribute instances that represent attributes contained in this element. This value would be nil if the element has no attributes.

55.3.3Method

xml.element#addchild
xml.element#addchild(value):map:void

xml.element#gettext
xml.element#gettext()

xml.element#textize
xml.element#textize(fancy?:boolean, indentLevel?:number, tabs?:number)

xml.element#write
xml.element#write(stream:stream:w, fancy?:boolean, indentLevel?:number, tabs?:number):void

55.4xml.parser Class

The xml.parser class is a base class from which you can implement a inheritance class that has methods corresponding to events associated with XML elements. Below are methods that you can implement in the class for event handling:

55.4.1Constructor

xml.parser
xml.parser() {block?}

55.4.2Method

xml.parser#parse
xml.parser#parse(stream:stream:r):void

55.5Thanks

This module uses expat library which is distributed in the following site:

http://expat.sourceforge.net/


Copyright (C) 2011-2017 ypsitau