xml/dom.bi

Summary
xml/dom.bi
About this ModuleThis is the XML-DOM api module.
Code LicenseCopyright © 2007-2014, FreeBASIC Extended Library Development Group
ext.xml
Enumerations
node_type_eRepresents the different types of nodes supported.
nodeChild XML class, branch and leaf nodes.
Variables
tagContains this child’s tag name
Functions
node_typeAccess the type of the node.
Properties
attributeAccess the value of an attribute of the node.
attributeSet the value of an attribute of this node.
getTextReturns the value of a Text element.
setTextSets the value of a Text element.
Functions
childrenCount the number of child nodes.
childrenCount the number of child nodes with a specific tag.
childrenCount the number of child nodes with a specific type.
childAccess a specific child of this node.
childAccess a specific child of this node by tag.
childAccess a specific child of this node by type.
last_childAccess the child with the highest integer index.
appendChildAdd a child onto this node.
remove_childRemove a child from this node.
remove_childRemove a child from this node by tag.
remove_childRemove a child from this node by type.
Parent( ) as node ptr
treeBase XML class, node is a sub-class of this class.
Variables
rootUsed to access the XML document structure.
Functions
loadLoads a XML data structure from a file.
unloadUnloads a XML data structure to a file
clearClears all data from the xml tree.

About this Module

This is the XML-DOM api module.  This allows you to parse small XML documents rapidly using a simple interface.

For a simple example of creating a document using this interface see https://code.google.com/p/fb-extended-lib/source/browse/examples/xml/simple.bas or for a more advanced example of document creation see https://code.google.com/p/fb-extended-lib/source/browse/examples/xml/advanced.bas.  You can also look in the examples/xml folder for more examples.

Code License

Copyright © 2007-2014, FreeBASIC Extended Library Development Group

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com/p/fb-extended-lib/wiki/License

ext.xml

Summary
Enumerations
node_type_eRepresents the different types of nodes supported.

Enumerations

node_type_e

Represents the different types of nodes supported.

Valid values are

  • element
  • text
  • comment
  • processingInstruction
  • cdata
  • declaration

node

Child XML class, branch and leaf nodes.

Supports casting to string to print out XML data of the node and its children.  Any Unicode characters in the XML are internally converted to UTF-8.

Summary
Variables
tagContains this child’s tag name
Functions
node_typeAccess the type of the node.
Properties
attributeAccess the value of an attribute of the node.
attributeSet the value of an attribute of this node.
getTextReturns the value of a Text element.
setTextSets the value of a Text element.
Functions
childrenCount the number of child nodes.
childrenCount the number of child nodes with a specific tag.
childrenCount the number of child nodes with a specific type.
childAccess a specific child of this node.
childAccess a specific child of this node by tag.
childAccess a specific child of this node by type.
last_childAccess the child with the highest integer index.
appendChildAdd a child onto this node.
remove_childRemove a child from this node.
remove_childRemove a child from this node by tag.
remove_childRemove a child from this node by type.
Parent( ) as node ptr

Variables

tag

as string tag

Contains this child’s tag name

Functions

node_type

declare function nodeType() as node_type_e

Access the type of the node.

Returns

node_type_e, this node’s type.

Properties

attribute

declare property attribute(byref attribute as const string) as string

Access the value of an attribute of the node.

Parameters

attributethe name of the attribute you wish to retrieve.

Returns

string, the requested attribute’s value.

attribute

declare property attribute(byref attribute as const string,
byref new_value as const string)

Set the value of an attribute of this node.

Parameters

attributethe name of the attribute
new_valuethe value to assign to attribute

getText

declare property getText( ) as string

Returns the value of a Text element.

setText

declare property setText(byref text_ as const string)

Sets the value of a Text element.

Parameters

text_the value to assign to the Text element.

Functions

children

declare function children() as integer

Count the number of child nodes.

Returns

integer, count of children of this node.

children

declare function children(byref tag as const string) as integer

Count the number of child nodes with a specific tag.

Parameters

tagtag to limit count.

Returns

integer, count of children of this node matching the specified tag.

children

declare function children(byval node_type as node_type_e) as integer

Count the number of child nodes with a specific type.

Parameters

node_typenode type to limit count.

Returns

integer, count of children of this node matching the specified type.

child

declare function child(byval index as integer =  0) as node ptr

Access a specific child of this node.

Parameters

indexinteger index value of child.

Returns

node ptr, access with ->

child

declare function child(byref tag as const string,  
byval index as integer =  0) as node ptr

Access a specific child of this node by tag.

Parameters

tagtag to limit index to.
indexinteger index value of child.

Returns

node ptr, access with ->

child

declare function child(byval node_type as node_type_e,  
byval index as integer =  0) as node ptr

Access a specific child of this node by type.

Parameters

node_typenode type to limit index to.
indexinteger index value of child.

Returns

node ptr, access with ->

last_child

Access the child with the highest integer index.

Returns

node ptr, access with ->

appendChild

declare function appendChild(
   byref tag as const string,  
   byval node_type as node_type_e =  element
) as node ptr

Add a child onto this node.

Parameters

tagtag to give new child.
node_typeoptional type of node to create, defaults to element.

Returns

node ptr of the new child, not needed for normal usage.

remove_child

Remove a child from this node.

Parameters

indexinteger index of node to remove.

remove_child

Remove a child from this node by tag.

Parameters

tagtag of node to limit index to.
indexinteger index of node to remove.

remove_child

Remove a child from this node by type.

Parameters

node_typenode type to limit index to.
indexinteger index of node to remove.

Parent( ) as node ptr

tree

Base XML class, node is a sub-class of this class.

Supports casting to a string to print all XML data.

Summary
Variables
rootUsed to access the XML document structure.
Functions
loadLoads a XML data structure from a file.
unloadUnloads a XML data structure to a file
clearClears all data from the xml tree.

Variables

root

as node ptr root

Used to access the XML document structure.

Functions

load

declare function load(byref xmlfile as const string) as bool

Loads a XML data structure from a file.

Parameters

xmlfilethe file to load

Returns

bool, returns false on success, true on error.

unload

declare function unload(byref xmlfile as const string) as bool

Unloads a XML data structure to a file

this does not destroy the structure

Parameters

xmlfilethe file to unload to

Returns

bool, returns false on success, true on error.

clear

declare sub clear( )

Clears all data from the xml tree.

as string tag
Contains this child’s tag name
declare function nodeType() as node_type_e
Access the type of the node.
declare property attribute(byref attribute as const string) as string
Access the value of an attribute of the node.
declare property getText( ) as string
Returns the value of a Text element.
declare property setText(byref text_ as const string)
Sets the value of a Text element.
declare function children() as integer
Count the number of child nodes.
declare function child(byval index as integer =  0) as node ptr
Access a specific child of this node.
declare function appendChild(
   byref tag as const string,  
   byval node_type as node_type_e =  element
) as node ptr
Add a child onto this node.
as node ptr root
Used to access the XML document structure.
declare function load(byref xmlfile as const string) as bool
Loads a XML data structure from a file.
declare function unload(byref xmlfile as const string) as bool
Unloads a XML data structure to a file
declare sub clear( )
Clears all data from the xml tree.