libxml2 XML parsing object


Usage:

OBJECT x = CREATE "dynamic", "klibxml"

If an application wishes to use the libxml2 XML parsing object then it should load it once and keep it loaded. Loading it each time it is used is very inefficient.

The writeToString method as implemented in KCML 6.20 has a memory leak. See the notes on the method on how to avoid it.

For further information see http://xmlsoft.org


Root
Parser
Document
Element
Node
XPath
NamedNodeMap
NodeList
MemBufInputSource
Implementation
Comment
CDATASection
ProcessingInstruction
Text
CharacterData
DocumentFragment
EntityReference
Attr
Writer
WriterFilter
MemBufOutput
SAXParser
ContentHandler
Namespaces
Attributes
ScanToken
NodeFilter
NodeIterator
TreeWalker
TextReader
Transformer

Root

XML root object

This software contains code developed by the Gnome XML project (http://xmlsoft.org) (Daniel Veillard et al.) and is licensed under an MIT license.
MethodReturnsPurpose
CreateTransformer()KXML_TRANSFORMCreates transformer objectKCML
HasFeature(feature)BOOLReturn TRUE if a feature was compiled into libxml2
createParser()ParserCreates DOM parser objectKCML
createSAXParser()SAXParserCreates a SAX2 parser objectKCML
createXMLTextReader()TextReaderCreates an XmlTextReader objectKCML
getDOMImplementation(name$)ImplementationReturn an Implementation ref from DOM Implementation RegistryKCML
PropertyTypeReturnsPurpose
ImplementationRImplementationReturn an Implementation refKCML

Parser

Parser object

MethodReturnsPurpose
MemBufInputSource(buf, buflen, id)MemBufInputSourceConstructor for a memory buffer input stream
ParseMemory(buf, buflen)voidParse from a stringKCML
ProcessXInclude()integerProcess any XInclude directives in the parsed document, returns the number of substitutions done or -1 for error
parse(URI$)voidParse a URI
parseIS(OBJECT stream)voidParse from an inputstreamKCML
reset()voidReset parser state ready for another parse
resetDocumentPool()voidFree any documents associated with the parser
PropertyTypeReturnsPurpose
CreateEntityReferenceNodesRWBOOLGet/set flag controlling expansion of entities
DoNamespacesRWBOOLGet/set process namespaces flag
DoSchemaRWBOOLGet/set Process schemas flag
DocumentRDocumentReturn document object
ErrorCountRintGet error count from last parse
ExitOnFirstFatalErrorRWBOOLGet/set Exit On First Fatal Error flag
IncludeIgnorableWhitespaceRWBOOLGet/set flag controlling how whitespace is treated (requires DTD)
LoadExternalDTDRWBOOLGet/set flag to control loading of an external DTD. If the DTD is referenced only for consistency checking and is not needed during the parse, say to supply entities, then set this flag to FALSE.
ValidationConstraintFatalRWBOOLGet/set Validation Constraint Fatal flag
ValidationSchemeRWValSchemeGet/set validation scheme

Document

DOM Document object

Extends Node

MethodReturnsPurpose
ProcessXInclude()integerProcess any XInclude directives in the document, returns the number of substitutions done or -1 for error
createAttribute(name$)AttrCreate a new attribute node with given name
createAttributeNS(pszURI$, pszQName$)AttrCreate a new attribute node with given qualified name
createCDATASection(data$)CDATASectionCreate a new CDATA node for given data
createComment(text$)CommentCreate a new Comment node for given text
createDocumentFragment()DocumentFragmentCreate an empty DocumentFragment object
createElement(tagname$)ElementCreate a new Element node
createElementNS(pszURI$, pszQName$)ElementCreate a new Element node
createEntityReference(pszName$)EntityReferenceCreate a new Entity reference node
createNodeFilter()NodeFilterCreate a node filter objectKCML
createNodeIterator(OBJECT root, nWhatToShow, OBJECT filter, bExpandEntities)NodeIteratorCreate a flat tree NodeIterator
createProcessingInstruction(target$, data$)ProcessingInstructionCreate a new Processing Instruction node
createTextNode(data$)ElementCreate a new Text node
createTreeWalker(OBJECT root, nWhatToShow, OBJECT filter, bExpandEntities)TreeWalkerCreate a flat tree DOM walker
createWriterFilter()WriterFilterCreate a serialization WriterFilter objectKCML
createXPath()XPathCreate an XPath object
getElementById(id$)NodeReturn element matching an ID
getElementsByTagName(pattern$)NodeListMake node list of elements matching a tag name or '*'.
getElementsByTagNameNS(NsURI$, localname$)NodeListGet a node list of elements matching by NS URI and local name
importNode(OBJECT importnode, deep)NodeImport a node from another document
normalizeDocument()voidNormalize a document as if it had been saved and loaded again
PropertyTypeReturnsPurpose
ActualEncoding$RWstringGet/set actual encoding of document
DoctypeRDocumentTypeReturns the document type declaration
DocumentElementRElementReturns the documents root element
DocumentURI$RWstringGet/set document location, NULL if undefined
Encoding$RWstringGet/set document encoding
ImplementationRImplementationReturns the implementation object that handles the doc
StandaloneRWBOOLGet/set standalone
StrictErrorCheckingRWBOOLGet/set error checking on node operations
Version$RWstringGet/set document version string

Element

DOM Element object

Extends Node

MethodReturnsPurpose
getAttribute$(name$)stringGet attribute of element by name
getAttributeNS$(NsURI$, localname$)stringGet attribute of element by name
getAttributeNode(name$)AttrGet a Attr node object by name
getAttributeNodeNS(NsURI$, localname$)AttrGet a Attr node object by name
getElementsByTagName(pattern$)NodeListMake node list of elements under this element matching a tag name or '*'.
getElementsByTagNameNS(NsURI$, localname$)NodeListGet a node list of elements under this element matching by NS URI and local name
removeAttribute(name$)voidRemove attribute of element by name
removeAttributeNS(NsURI$, localname$)voidRemove attribute of element by name
removeAttributeNode(OBJECT name)AttrRemove specified Attr node
setAttribute(name$, value$)voidSet attribute of element by name
setAttributeNS(NsURI$, qualname$, value$)voidSet attribute of element by name
setAttributeNode(OBJECT newattr)AttrAdds or replaces an Attr node
setAttributeNodeNS(OBJECT newattr)AttrAdds or replaces an Attr node
PropertyTypeReturnsPurpose
TagName$RstringReturn name of the element

Node

DOM Node object

Downcastable from the following interfaces:

Text
Element
CharacterData
Document
Attr

MethodReturnsPurpose
appendChild(OBJECT newChild)NodeAdd child to list of children
cloneNode(deep)NodeClone this node
hasChildNodes()BOOLReturn true if node has children
insertBefore(OBJECT newChild, OBJECT refChild)NodeInsert node before existing child node
normalize()voidNormalize children
release()voidFree resourcesXerces
removeChild(OBJECT oldChild)NodeDelete child oldchild from the list of children and return it
replaceChild(OBJECT newChild, OBJECT oldChild)NodeReplace existing child with newchild and return oldChild
PropertyTypeReturnsPurpose
AttributesRNamedNodeMapReturn a NamedNodeMap of the attributes of the node or NULL
ChildNodesRNodeListReturn all children in a nodelist
FirstChildRNodeReturn first child of a node
LastChildRNodeReturn last child of a node
LocalName$RstringReturn local part of the qualified name of this node
NamespaceURI$RstringReturn namespace URI for node tag
NextSiblingRNodeReturn next sibling of a node
NodeName$RstringReturn name of a node (with NS prefix if applicable)
NodeTypeRintReturn type of a node
NodeValue$RstringReturn value of a node, depending on type
OwnerDocumentRDocumentGet the document associated with this node
ParentNodeRNodeReturn parent of a node
Prefix$RWstringGet/set namespace prefix of this node
PreviousSiblingRNodeReturn previous sibling of a node

XPath

XPath object

MethodReturnsPurpose
RegisterNS(pszPrefix$, pszURI$)voidRegister the NS URI that goes with a prefix used in the expression. You can use a blank URI for the default namespace.
SetCurrentNode(node)voidSet the current node for relative XPath expressions
evaluate(expr$)NodeListEvaluate an XPath expression returning a list of nodes
PropertyTypeReturnsPurpose
CurrentNodeRNodeThe current node for relative XPath expressions

NamedNodeMap

DOM Named Node Map object used for attributes

This collection can be iterated with FOR OBJECT ... NEXT OBJECT

MethodReturnsPurpose
getNamedItem(name$)NodeReturn node with given name
item(index)NodeReturn node with given index (zero based)
PropertyTypeReturnsPurpose
LengthRunsigned intReturn count of nodes in the map

NodeList

DOM Node List object

This collection can be iterated with FOR OBJECT ... NEXT OBJECT

MethodReturnsPurpose
item(index)NodeReturn node with given index (zero based)
PropertyTypeReturnsPurpose
LengthRintReturn count of nodes in a node list

MemBufInputSource

Memory buffer based input stream object


Implementation

DOM Implementation object

MethodReturnsPurpose
createDOMWriter()WriterCreate a Writer serializing objectDOM3
createDocument(NamespaceURI$, qualifiedName$, OBJECT doctype)DocumentCreates a new XML Document object
createDocument()DocumentCreates a nameless XML document object
createDocumentType(qualifiedName$, publicId$, systemId$)DocumentTypeCreates a new XML DocumentType node i.e. a DTD ref
hasFeature(feature$, version$)BOOLreturns TRUE if a feature is supported
PropertyTypeReturnsPurpose
ImplementationRImplementationReturn a Implementation ref for this object

Comment

DOM Comment object

Extends CharacterData


CDATASection

DOM CDATA object

Extends Text


ProcessingInstruction

DOM ProcessingInstruction object

Extends Node

PropertyTypeReturnsPurpose
Data$RstringGet/set data of the element
Target$RstringReturn target of the element

Text

DOM Text object

Extends Node

MethodReturnsPurpose
isIgnorableWhitespace()BOOLReturns TRUE if node contains only ignorable whitespace (requires a DTD)
isWhitespace()BOOLReturns TRUE if node is empty or contains only whitespaceKCML

CharacterData

DOM Character object

Extends Node


DocumentFragment

DOM DocumentFragment object

Extends Node


EntityReference

DOM EntityReference object

Extends Node


Attr

DOM Attribute object

Extends Node

PropertyTypeReturnsPurpose
Name$RstringReturn name of the attribute
OwnerElementRElementReturn Element node the attribute is attached to or NULL if none
SpecifiedRBOOLReturn TRUE if the attribute was explicitly specified rather than assumed from the DTD default
Value$RWstringGet/set value of the attribute

Writer

Used to serialize a document

MethodReturnsPurpose
canSetFeature(feature$, value)boolIndicates whether setting a feature to a particular value will be supportedDOM3
getFeature(feature$)boolGet the value of a standardized featureDOM3
setFeature(feature$, value)voidSet the value of a standardized featureDOM3
setFilter(OBJECT filter)voidApply a WriterFilter object to filter the serialized outputDOM3
writeDocToFile(OBJECT doc, file$)integerSerialize a UTF-8 encoded document to a file. Returns number of bytes written or -1 for an error.KCML
writeDocToString(OBJECT doc)MemBufOutputSerialize a UTF-8 encoded document to a string objectKCML
writeToString(OBJECT node)MemBufOutputSerialize a node to a string objectDOM3
PropertyTypeReturnsPurpose
Encoding$RWstringGet/Set encoding to use when serializing. NULL means UTF-8.DOM3
NewLine$RWstringGet/Set end-of-line sequence to use when serializing. Only HEX(0A), HEX(0D) and HEX(0D0A) are acceptable. NULL means OS default.DOM3

WriterFilter

Object that receives filter callbacks during serialization

The acceptNode() callback function returns the same enumeration as the NodeFilter callbacks namely
DIM _FILTER_ACCEPT=1, _FILTER_REJECT=2, _FILTER_SKIP=3

MethodReturnsPurpose
SetFilter(fn)voidSet KCML callback for filtering a node
CallbackReturnsPurpose
acceptNode(node)integer
PropertyTypeReturnsPurpose
WhatToShowRWintegerGet/Set types of nodes to be serialized

MemBufOutput

String object

PropertyTypeReturnsPurpose
Text$RstringReturn UTF-8 textKCML

SAXParser

SAX2 Parser object

MethodReturnsPurpose
ContentHandler()ContentHandlerConstructor for a SAX2 ContentHandler objectKCML
createScanToken()ScanTokenAllocate a ScanToken for use in a progressive parseKCML
parse(URI$)voidParse a URI
parseFirst(URI$, OBJECT token)BOOLStart a progressive parse of a URI
parseFirstIS(OBJECT stream, OBJECT token)BOOLStart a progressive parse of an InputStream
parseIS(OBJECT stream)voidParse from an InputStream
parseNext(OBJECT token)BOOLContinue a progressive parse
parseReset(OBJECT token)voidReset the parser after a progressive parse
setContentHandler(OBJECT handler)voidSpecify the SAX2 ContentHandler
PropertyTypeReturnsPurpose
ErrorCountRintGet error count from last parse
ExitOnFirstFatalErrorRWBOOLGet/set Exit On First Fatal Error flag
ValidationConstraintFatalRWBOOLGet/set Validation Constraint Fatal flag

ContentHandler

Object that receives callbacks from SAX2 events

MethodReturnsPurpose
SetCharacters(fn)voidSet KCML handler subroutine for characters
SetEndDocument(fn)voidSet KCML handler subroutine for end of document
SetEndElement(fn)voidSet KCML handler subroutine for end of element
SetIgnorableWhitespace(fn)voidSet KCML handler subroutine for DTD defined ignorable whitespace
SetResetDocument(fn)voidSet KCML handler subroutine for restart of document
SetStartDocument(fn)voidSet KCML handler subroutine for start of document
SetStartElement(fn)voidSet KCML handler subroutine for start of element
CallbackReturnsPurpose
characters(text$, length)voidReceive notification of text. Note that the length is the number of bytes in the UTF-8 string. This handler may be called more than once for a text string which contains entities.
endDocument()voidReceive notification of end of document
endElement(URI$, localname$, qname$)voidReceive notification of end of every element
ignorableWhitespace(text$, length)voidReceive notification of DTD defined ignorable whitespace
startDocument()voidReceive notification of start of document
startElement(uri$, localname$, qname$, atts)voidReceive notification of start of every element, uri$ is the combination of the NS and the tag as a URI, localname$ is the bare tag name, qname$ is the tag with its prefix,attributes is an object containing any attributes for the tag
PropertyTypeReturnsPurpose
ObjDefRconst DYN_DEF *

Namespaces

Namespaces collection returned by SAX2 with an element node

PropertyTypeReturnsPurpose
ObjDefRconst DYN_DEF *

Attributes

Attributes collection returned by SAX2 with an element node

MethodReturnsPurpose
LocalName$(index)stringReturns the local name of an attribute in the list by index (0 based)
QName$(index)stringReturns the qualified name of an attribute in the list by index (0 based)
URI$(index)stringReturns the namespace URI of an attribute in the list by index (0 based)
Value$(index)stringReturns the value of an attribute in the list by position
Value$(qname$)stringReturns the value of an attribute in the list by qualified name
Index(qname$)integerReturns the index of an attribute in the list by qualified name
Index(uri$, localpart$)integerReturns the index of an attribute in the list by namespace name
PropertyTypeReturnsPurpose
DefaultedAttributesRintReturns the number of attributes for the element defaulted by the DTD
LengthRintReturns the number of attributes for the element
ObjDefRconst DYN_DEF *

ScanToken

Scan state token for progressive parsing


NodeFilter

Object that receives filter callbacks from NodeIterator and TreeWalker

The acceptNode() callback function returns one of the following enumeration
DIM _FILTER_ACCEPT=1, _FILTER_REJECT=2, _FILTER_SKIP=3

MethodReturnsPurpose
SetFilter(fn)voidSet KCML callback for filtering a node
CallbackReturnsPurpose
acceptNode(node)integer

NodeIterator

DOM NodeIterator object

MethodReturnsPurpose
nextNode()NodeReturn next node in list
previousNode()NodeReturn previous node in list
PropertyTypeReturnsPurpose
ExpandEntityReferencesRBOOLReturn original ExpandEntityReferences flag
RootRNodeOriginal root node specified when list was created
WhatToShowRintegerReturn bitmap of node types included

TreeWalker

DOM TreeWalker object

MethodReturnsPurpose
firstChild()NodeMoves to first child and returns the node
getCurrentNode()NodeGet node at which the NodeWalker is positioned
lastChild()NodeMoves to last child and returns the node
nextNode()NodeMoves to and returns next node in list
nextSibling()NodeMoves to next sibling and returns the node
parentNode()NodeMoves to and returns the closest visible ancestor node of the current node in list
previousNode()NodeMoves to and returns previous node in list
previousSibling()NodeMoves to previous sibling and returns the node
setCurrentNode(OBJECT node)voidSet node at which the NodeWalker is positioned
PropertyTypeReturnsPurpose
ExpandEntityReferencesRBOOLReturn original ExpandEntityReferences flag
RootRNodeOriginal root node specified when list was created
WhatToShowRintegerReturn bitmap of node types included

TextReader

TextReader object for progressive parsing

MethodReturnsPurpose
Expand()NodeExpand the DOM tree below the current node and return that node
GetAttributeByName$(name$)stringGet attribute using qualified name
GetAttributeByNameNS$(localname$, URI$)stringGet attribute using name and namespace
GetAttributeByindex$(index)stringGet attribute using a zero based index
ParseFile(File$)voidParse document from a file or URI
PreserveNode()NodePreserve the current node in the document
PreservePattern(Pattern$)intPreserve the nodes matching the XPath pattern
Read()intRead the next node in the document
Skip()intSkip to the next peer node in the document avoiding any subtree
PropertyTypeReturnsPurpose
AttributeCountRintGet the number of attributes for a node
CurrentDocRDocumentKeep document being parsed in this object
CurrentNodeRNodereturn the temporary node being parsed in this object
DefaultAttributesRWBOOLGet/set flag controlling defaulting of attributes using a DTD
DepthRintGet the tree depth of a node
Encoding$RstringGet/set document encoding
ErrorCountRintGet error count from last parse
ExpandEntityReferenceNodesRWBOOLGet/set flag controlling expansion of entities using a DTD
HasAttributesRBOOLTrue iff the node has attributes
HasValueRBOOLTrue iff the node can have a text value
IncludeIgnorableWhitespaceRWBOOLGet/set flag controlling how whitespace is treated (requires DTD)
IsValidRBOOLIs the parsing context valid
LastErr$RstringGet last error message
LoadExternalDTDRWBOOLGet/set flag to control loading of an external DTD. If the DTD is referenced only for consistency checking and is not needed during the parse, say to supply entities, then set this flag to FALSE.
NodeLocalName$RstringReturn local name of a node
NodeName$RstringReturn name of a node (with NS prefix if applicable)
NodeNamespaceURI$RstringReturn the namespace URI of a node
NodePrefix$RstringReturn prefix of a node
NodeTypeRintGet the DOM node type of a node
NodeValue$RstringGet the text value of a node, if applicable
ParserColumNumberRintGet the column number of the current parsing point
ParserLineNumberRintGet the line number of the current parsing point
ValidateRWBOOLGet/set flag controlling validation against a DTD

Transformer

XSL tranformer object

MethodReturnsPurpose
AddParameter(name$, value$)voidAdd a parameterKCML
AddStringParameter(name$, value$)voidAdd a string parameter that will be quotedKCML
ClearParameters()voidDrop all parametersKCML
TransformFile(src$, xsl$, dst$)integerTransform using filesKCML
TransformFile(src$, dst$)integerTransform using files and an embedded stylesheetKCML
PropertyTypeReturnsPurpose
LastError$RstringReturn text of last error