Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Pike Module Reference:

module version 1.24, prepared

  MODULE Public
Modules
Parser

  MODULE Public.Parser
Modules
XML2

  MODULE Public.Parser.XML2
Classes
Node
RelaxNG
SAX
Stylesheet
XMLReader

Methods
clear_xslt_docloader()
get_encoding_alias()
get_encoding_name()
get_encodings()
new_xml()
parse_html()
parse_relaxng()
parse_xml()
recover_xml()
render_html()
render_xml()
select_xpath_nodes()
set_auto_utf8_convert()
set_html_parser_options()
set_xml_parser_options()
set_xslt_docloader()
substituteEntitiesDefault()
utf8_check()
utf8_to_html()
utf8_to_isolat1()

Method select_xpath_nodes

array(object(Node)) Public.Parser.XML2.select_xpath_nodes(string xpath, object node)

Description

selects nodes based on an XPath query and returns the result.


Method set_xslt_docloader

void Public.Parser.XML2.set_xslt_docloader(function f)

Description

sets the xslt loader function. this is global for the process.

the callout should have the following signature:

Node f(string uri, int options, int type)

where: uri is the URI of the document to load options are a set of xmlParserOption the xsltLoadType indicating the kind of loading required


Method clear_xslt_docloader

void Public.Parser.XML2.clear_xslt_docloader()

Description

clears the system wide docloader callout, if one was set.


Method set_xml_parser_options

void Public.Parser.XML2.set_xml_parser_options(int options)

Description

sets parser options.

Parameter options

a bitwise or of Public.Parser.XML2.Constants options where valid options start with PARSE_.


Method set_auto_utf8_convert

void Public.Parser.XML2.set_auto_utf8_convert(int flag)

Description

sets whether the parser should automatically convert input to the parser to and from UTF-8. libxml2 requires input (aside from data to be parsed, which may be encoded differently) to be UTF-8 encoded. This module will automatically convert all string input to and from UTF-8. Calling this function with an argument of zero (0) will turn this feature off. In this case, you will be responsible for ensuring that any input is properly encoded (if necessary).

Parameter flag

a boolean value: 0 disables auto conversion, 1 enables.


Method set_html_parser_options

void Public.Parser.XML2.set_html_parser_options(int options)

Description

sets parser options.

Parameter options

a bitwise or of Public.Parser.XML2.Constants options where valid options start with PARSE_.


Method substituteEntitiesDefault

int Public.Parser.XML2.substituteEntitiesDefault(int def)


Method utf8_to_html

string Public.Parser.XML2.utf8_to_html(string str)


Method utf8_to_isolat1

string Public.Parser.XML2.utf8_to_isolat1(string str)


Method utf8_check

int Public.Parser.XML2.utf8_check(string str)


Method get_encodings

array(int) Public.Parser.XML2.get_encodings()

Description

gets the list of available character encoders.

Returns

an array of available encoder identifiers.


Method get_encoding_name

string Public.Parser.XML2.get_encoding_name(int e)


Method get_encoding_alias

string Public.Parser.XML2.get_encoding_alias(string e)


Method render_xml

string Public.Parser.XML2.render_xml(object(Node) n)

Description

Renders a node tree as an XML string. The entire document tree will be rendered. To render a portion of a tree, use Node.render_xml.

Parameter n

a Node object for a given XML document.


Method render_html

string Public.Parser.XML2.render_html(object(Node) n)

Description

Renders a node tree as an HTML string. The entire document tree will be rendered. To render a portion of a tree, use Node.render_html.

Parameter n

a Node object for a given HTML document.


Method recover_xml

object(Node) Public.Parser.XML2.recover_xml(string xml)

Description

Parse an string containing XML, even if it is not Well Formed.

Parameter xml

String containing XML data to parse.

Returns

a Node object containing the root of the tree.


Method parse_xml

object(Node) Public.Parser.XML2.parse_xml(string xml, string|void name, string|void encoding)

Description

Parse an string containing XML.

Parameter xml

String containing XML data to parse.

Parameter name

String containing name/URI of file.

Returns

a Node object containing the root of the tree.


Method parse_html

object(Node) Public.Parser.XML2.parse_html(string html, string|void name, string|void encoding)

Description

Parse an string containing HTML.

Parameter html

String containing HTML data to parse.

Parameter name

String containing name/URI of file.

Returns

a Node object containing the root of the tree.


Method new_xml

object(Node) Public.Parser.XML2.new_xml(string version)

Description

Create a new XML document with a root node.

Parameter version

the version of XML to create

Parameter root_name

the name of the root node

Returns

a Node object containing the root of the tree.


Method parse_relaxng

object(Node) Public.Parser.XML2.parse_relaxng(string relaxng, string|void name)

Description

Parse a string containing an RelaxNG schema.

Parameter name

String containing name/URI of file.

Returns

a RelaxNG object containing the parsed schema.

  CLASS Public.Parser.XML2.Node
Methods
()
add_child()
add_content()
add_next_sibling()
add_ns()
add_prev_sibling()
add_sibling()
children()
copy()
copy_list()
delete()
delete_attribute()
get_attributes()
get_base()
get_lang()
get_last_child()
get_line_no()
get_no_ns_attributes()
get_node_name()
get_node_path()
get_node_type()
get_ns()
get_ns_attributes()
get_nss()
get_root_node()
get_space_preserve()
get_text()
is_blank()
is_text()
new_cdata_block()
new_char_ref()
new_child()
new_comment()
new_doc_comment()
new_pi()
new_text_child()
next()
parent()
prev()
render_html()
render_xml()
replace()
set_base()
set_content()
set_lang()
set_node_name()
set_ns()
set_root_node()
unlink()

Method get_line_no

int Public.Parser.XML2.Node()->get_line_no()

Returns

the line number the node is present on


Method set_ns

object(Node) Public.Parser.XML2.Node()->set_ns(string ns_prefix)


Method set_content

object(Node) Public.Parser.XML2.Node()->set_content(string content)

Description

sets the content for a node


Method add_content

object(Node) Public.Parser.XML2.Node()->add_content(string content)

Description

appends the content for a node


Method get_text

string Public.Parser.XML2.Node()->get_text()

Description

gets the contents of a text node, or the contents and children of an element, or the value of an attribute node.


Method get_node_path

string Public.Parser.XML2.Node()->get_node_path()

Description

returns an XPath/XQuery based path for this Node.


Method get_ns

string Public.Parser.XML2.Node()->get_ns()

Description

returns the default name space uri for the element


Method get_nss

mapping Public.Parser.XML2.Node()->get_nss()

Description

gets a list of all known namespaces for this element.

Returns

a mapping of "short" prefixes to namespace uris.


Method get_base

string Public.Parser.XML2.Node()->get_base()


Method get_lang

string Public.Parser.XML2.Node()->get_lang()


Method get_space_preserve

int Public.Parser.XML2.Node()->get_space_preserve()


Method get_attributes

mapping Public.Parser.XML2.Node()->get_attributes()

Description

returns all attributes, irrespective of namespace

Returns

a mapping of attribute name to attribute value.


Method get_no_ns_attributes

mapping Public.Parser.XML2.Node()->get_no_ns_attributes()

Description

returns all attributes not present in a namespace

Returns

a mapping of attribute name to attribute value.


Method get_ns_attributes

mapping Public.Parser.XML2.Node()->get_ns_attributes(string ns_prefix)

Description

given a namespace uri, return all elements for that namespace present in the element.

Returns

a mapping of attribute names to attribute values.


Method children

array Public.Parser.XML2.Node()->children()

Description

get all children of this node

Returns

an array of all elements with are a direct child of this element.


Method parent

object(Node) Public.Parser.XML2.Node()->parent()

Description

get the Node which is the parent of this Node.


Method replace

object(Node) Public.Parser.XML2.Node()->replace()

Description

replace this node with a different node. if the new node was already inserted into a document, it is first unlinked from its original document.

Returns

the old node


Method copy

object(Node) Public.Parser.XML2.Node()->copy(void|int extended)

Description

copy a node

Parameter extended

if 1 do a recursive copy (properties, namespaces and children when applicable) if 2 copy properties and namespaces (when applicable)

Returns

the newly copied node.


Method copy_list

object(Node) Public.Parser.XML2.Node()->copy_list()

Description

recursively copy a node list

Returns

the newly copied node.


Method unlink

object(Node) Public.Parser.XML2.Node()->unlink()

Description

unlink a node from its current context. the node not freed. to unlink and destroy the node, use delete.

Returns

the unlinked node.


Method delete

void Public.Parser.XML2.Node()->delete()

Description

unlink a node and remove it (and its children) from memory


Method get_root_node

object(Node) Public.Parser.XML2.Node()->get_root_node()

Description

get the Node which is the root of this tree.


Method set_root_node

object(Node) Public.Parser.XML2.Node()->set_root_node()

Description

set this Node to be the root of this tree.

Returns

the old root of the tree, if any existed.


Method new_cdata_block

object(Node) Public.Parser.XML2.Node()->new_cdata_block(string contents)

Description

returns an unlinked CDATA block.


Method new_pi

object(Node) Public.Parser.XML2.Node()->new_pi(string name, string contents)

Description

returns an unlinked Processing Instruction node.


Methods

object(Node) Public.Parser.XML2.Node()->set_attribute(string name, string value)
object(Node) Public.Parser.XML2.Node()->set_ns_attribute(string name, string ns, string value)

Parameter ns

the namespace prefix

sets a new attribute, overwriting any existing value. if value is zero, the attribute will be removed from the node.


Method delete_attribute

object Public.Parser.XML2.Node()->delete_attribute(string name, string|void ns)

Parameter name

the name of the attribute to delete

Parameter ns

the prefix of the namespace containing the attribute to be deleted


Method new_char_ref

object(Node) Public.Parser.XML2.Node()->new_char_ref(string name)

Description

returns an unlinked character reference node.


Method new_comment

object(Node) Public.Parser.XML2.Node()->new_comment(string content)

Description

returns an unlinked comment node.


Method new_doc_comment

object(Node) Public.Parser.XML2.Node()->new_doc_comment(string content)

Description

returns an unlinked character reference node.


Method new_child

object(Node) Public.Parser.XML2.Node()->new_child(string|void ns, string name, string content)

Description

add a new child element, added to end of children for this node.

Parameter ns

the prefix of the namespace for the node (optional)

See also

new_text_child


Method new_text_child

object(Node) Public.Parser.XML2.Node()->new_text_child(string|void ns, string name, string content)

Description

add a new child element, added to end of children for this node. differs from new_child in that XML reserved entities present in content (such as amersand, greater-than and less-than) will be automatically replaced by their XML escaped entity representations.

Parameter ns

the prefix of the namespace for the node (optional)

See also

new_child


Method add_ns

object(Node) Public.Parser.XML2.Node()->add_ns(string href, string prefix)


Method add_child

object(Node) Public.Parser.XML2.Node()->add_child(object(Node) child)

Description

add a node to end of children for this node.


Method add_sibling

object(Node) Public.Parser.XML2.Node()->add_sibling(object(Node) sibling)

Description

add a node to end of siblings for this node.


Method add_next_sibling

object(Node) Public.Parser.XML2.Node()->add_next_sibling(object(Node) sibling)

Description

add a sibling node after this node.


Method add_prev_sibling

object(Node) Public.Parser.XML2.Node()->add_prev_sibling(object(Node) sibling)

Description

add a sibling node after this node.


Method get_last_child

object(Node) Public.Parser.XML2.Node()->get_last_child()

Description

get the Node which is the last child of this Node.


Method next

object(Node) Public.Parser.XML2.Node()->next()

Description

get the next sibling of this Node.

Returns

the next node which is a sibling of this node.


Method prev

object(Node) Public.Parser.XML2.Node()->prev()

Description

get the previous sibling of this Node.

Returns

the previous node which is a sibling of this node.


Method is_blank

int Public.Parser.XML2.Node()->is_blank()

Description

is this node empty?


Method is_text

int Public.Parser.XML2.Node()->is_text()

Description

is this a text node?


Method get_node_type

int Public.Parser.XML2.Node()->get_node_type()

Description

get the type of node.

Returns

the integer node type. Node type constants are defined in Public.Parser.XML2.Constants.


Method get_node_name

string Public.Parser.XML2.Node()->get_node_name()

Description

gets the name of this node, if it has one.


Method set_node_name

object Public.Parser.XML2.Node()->set_node_name(string name)

Description

sets the name of this node.


Method set_lang

object Public.Parser.XML2.Node()->set_lang(string language)

Description

sets the language of this node.


Method set_base

object Public.Parser.XML2.Node()->set_base(string uri)

Description

sets the base URI of this node.


Method render_xml

string Public.Parser.XML2.Node()->render_xml(int level, int format)

Description

renders the node and all children as xml (which will be encoded as UTF-8 by default).

Parameter level

the indentation level to use

Parameter format

should the xml be formated for ease of human reading. this setting only takes effect if Public.Parser.XML2.xmlKeepBlanksDefault(0) has been called.


Method render_html

string Public.Parser.XML2.Node()->render_html()

Description

renders the node and all children as html (which will be encoded as UTF-8 by default).

  CLASS Public.Parser.XML2.RelaxNG
Methods
validate_doc()
Description

a Relax-NG validator.


Method validate_doc

int Public.Parser.XML2.RelaxNG()->validate_doc(object(Node) node)

Description

Validates an XML document.

Returns

0 if the document is valid, a positive error code number otherwise and -1 in case of internal or API error.

  CLASS Public.Parser.XML2.SAX
Methods
clear_callback()
end()
feed()
parse()
set_callback()
Description

a SAX v1 parser featuring both pull and push (chunked) parsing.


Method set_callback

void Public.Parser.XML2.SAX()->set_callback(int callback_id, function f, mixed ... extra_args)

Description

sets a SAX handler callback function.

Parameter callback_id

the id of the type of handler you wish to set. this should be one of the Public.Parser.XML2.Constants.SAX_CB_* members.

Parameter f

the function to call when the selected parsing event occurs. prototypes for each event function are found in Public.Parser.XML2.SAXHandlers.

Parameter extra_args

extra data to supply to the callback function. these will be passed as extra parameters after any provided by the parser.

void serror_cb(mapping(string:mixed) error, mixed ... extra_args); mapping elements: domain, code, message, level, line, column

void entitydecl_cb(string name, int type, string publicId, string systemId, string content, mixed ... extra_args);

void elementdecl_cb(string name, int type, mixed ... extra_args);

void unparsedentitydecl_cb(string name, string publicId, string systemId, string notationName, mixed ... extra_args);

void attributedecl_cb(string elem, string fullname, int type, int def, string defaultValue, mixed ... extra_args);

void notationdecl_cb(string name, string publicId, string systemId, mixed ... extra_args);

void internalsubset_cb(string name, string ExternalId, string SystemId, mixed ... extra_args);

void externalsubset_cb(string name, string ExternalId, string SystemId, mixed ... extra_args);

void processinginstruction_cb(string target, string data, mixed ... extra_args);

void endelement_cb(string name, mixed ... extra_args);

void cdatablock_cb(string chars, mixed ... extra_args);

void ignorablewhitespace(string chars, mixed ... extra_args);

void characters_cb(string chars, mixed ... extra_args);

void reference_cb(string name, mixed ... extra_args);

void comment_cb(string value, mixed ... extra_args);

void startelement_cb(string name, mapping(string:string) attributes, mixed ... extra_args);

int isstandalone_cb(mixed ... extra_args);

void startdocument_cb(mixed ... extra_args);

void enddocument_cb(mixed ... extra_args);

int hasinternalsubset(mixed ... extra_args);

int hasexternalsubset(mixed ... extra_args);

string resolveentity(string publicId, string systemId, mixed ... extra_args);


Method clear_callback

int Public.Parser.XML2.SAX()->clear_callback(int callback_id)

Description

clears a SAX handler callback.

Parameter callback_id

the id of the type of handler you wish to set. this should be one of the Public.Parser.XML2.Constants.SAX_CB_* members.

Returns

1 if the handler existed, 0 otherwise.


Method feed

int Public.Parser.XML2.SAX()->feed(string d, string|void encoding)

Description

feed some XML data to the parser. feed may be called multiple times to pass an entire XML document to the parser. The document will be processed as data is fed to the parser.

Parameter d

some XML data to be parsed. need not be a complete XML document.

Returns

the number of bytes processed.


Method end

int Public.Parser.XML2.SAX()->end()

Description

end parsing of a document and prepare for the next document.

resets the document parsing context and prepares for the next document. end should be called after the last chunk of data in an XML document has been passed to feed.


Method parse

int Public.Parser.XML2.SAX()->parse(string d, string|void encoding)

Description

feed a complete XML document to the parser. data from the document will be processed and any registered SAX handler callbacks will be called as SAX events occur. this method contains an implicit call to end, so that the context is prepared to receive a new document after this function returns.

you may call this method with an (ending) fragment of an XML document, as long as any previous data needed to produce a valid XML document has already been fed to the parser using feed.

Parameter d

some XML data to be parsed. need not be a complete XML document.

Returns

the number of bytes processed.

  CLASS Public.Parser.XML2.Stylesheet
Methods
apply()
output()
set_attributes()

Method apply

object(Node) Public.Parser.XML2.Stylesheet()->apply(object(Node) xml)

Description

apply the stylesheet object to an xml file.

Parameter xml

a Node object from the parsed XML document to apply. Any node from the XML document may be used.

Returns

a Node object for the transformed document.


Method output

string Public.Parser.XML2.Stylesheet()->output(object(Node) xml, int|void encoding)

Description

render the applied stylesheet Node to a string.

Parameter xml

the transformed xml object

Parameter encoding

an optional encoding for the string. if not supplied, defaults to ISO-8859-1 (ISO Latin 1). Valid options are found in Public.XML2.Constants, XML_CHAR_ENCODING*.

Returns

the string representation of the transformed XML.


Method set_attributes

void Public.Parser.XML2.Stylesheet()->set_attributes(mapping variables)

Description

set attributes for use by the stylesheet transformation

Note

Currently, the input to this function is assumed to be UTF-8 encoded. We should probably do that automagically.

  CLASS Public.Parser.XML2.XMLReader
Methods
attribute()
attribute_count()
attribute_no()
attribute_ns()
baseuri()
create()
depth()
element()
expand()
first_attribute()
get_attribute()
get_attribute_no()
get_attribute_ns()
get_parser_prop()
has_attributes()
has_value()
inner_xml()
is_default()
is_empty_element()
is_namespace_decl()
is_valid()
localname()
lookup_namespace()
name()
namespaceuri()
next()
next_attribute()
next_sibling()
node_type()
outer_xml()
parser_column_number()
parser_line_number()
prefix()
read()
set_parser_prop()
string()
value()
xml_lang()
Description

A simplified parser for XML documents. Similar to the C# XMLReader class.


Method read

int Public.Parser.XML2.XMLReader()->read()

Description

reads the next node of the document and loads its data.

returns 1 if a node was read, 0 if no additional nodes are available, and throws an error if a parse error occurred.


Method node_type

int Public.Parser.XML2.XMLReader()->node_type()

Description

returns the type of the current node. Types are described here: http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html


Method expand

object(Node) Public.Parser.XML2.XMLReader()->expand()


Method depth

int Public.Parser.XML2.XMLReader()->depth()

Description

returns the depth of the current node within the tree.


Method has_attributes

int Public.Parser.XML2.XMLReader()->has_attributes()

Description

Does the node have attributes?


Method attribute_count

int Public.Parser.XML2.XMLReader()->attribute_count()

Description

returns the number of attributes associated with the current node.


Method next_sibling

int Public.Parser.XML2.XMLReader()->next_sibling()


Method next

int Public.Parser.XML2.XMLReader()->next()


Method element

int Public.Parser.XML2.XMLReader()->element()


Method first_attribute

int Public.Parser.XML2.XMLReader()->first_attribute()


Method next_attribute

int Public.Parser.XML2.XMLReader()->next_attribute()


Method attribute_no

int Public.Parser.XML2.XMLReader()->attribute_no()


Method attribute_ns

int Public.Parser.XML2.XMLReader()->attribute_ns(string localName, string namespaceURI)


Method attribute

int Public.Parser.XML2.XMLReader()->attribute(string name)


Method has_value

int Public.Parser.XML2.XMLReader()->has_value()


Method is_default

int Public.Parser.XML2.XMLReader()->is_default()


Method is_namespace_decl

int Public.Parser.XML2.XMLReader()->is_namespace_decl()


Method is_empty_element

int Public.Parser.XML2.XMLReader()->is_empty_element()


Method is_valid

int Public.Parser.XML2.XMLReader()->is_valid()


Method parser_column_number

int Public.Parser.XML2.XMLReader()->parser_column_number()


Method parser_line_number

int Public.Parser.XML2.XMLReader()->parser_line_number()


Method get_parser_prop

int Public.Parser.XML2.XMLReader()->get_parser_prop(int prop)

Parameter prop

the property to get


Method set_parser_prop

int Public.Parser.XML2.XMLReader()->set_parser_prop(int prop, int value)

Parameter prop

the property to set

Parameter value

the value to set


Method name

string Public.Parser.XML2.XMLReader()->name()


Method get_attribute

string Public.Parser.XML2.XMLReader()->get_attribute(string name)


Method get_attribute_no

string Public.Parser.XML2.XMLReader()->get_attribute_no(int no)


Method get_attribute_ns

string Public.Parser.XML2.XMLReader()->get_attribute_ns(string localName, string namespaceURI)


Method lookup_namespace

string Public.Parser.XML2.XMLReader()->lookup_namespace(string|void prefix)


Method xml_lang

string Public.Parser.XML2.XMLReader()->xml_lang()


Method prefix

string Public.Parser.XML2.XMLReader()->prefix()


Method namespaceuri

string Public.Parser.XML2.XMLReader()->namespaceuri()


Method baseuri

string Public.Parser.XML2.XMLReader()->baseuri()


Method localname

string Public.Parser.XML2.XMLReader()->localname()


Method value

string Public.Parser.XML2.XMLReader()->value()


Method string

string Public.Parser.XML2.XMLReader()->string()


Method inner_xml

string Public.Parser.XML2.XMLReader()->inner_xml()


Method outer_xml

string Public.Parser.XML2.XMLReader()->outer_xml()


Method create

void Public.Parser.XML2.XMLReader()->create(string xml, string|void url, int|void options, string encoding)

Description

note that xml is expected to be encoded according to the encoding directive in the xml file, or as UTF-8. All other strings may be in Pike standard string format.

gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University