3.14. XML Functions

XML functions allow serializing and deserializing between XML strings and qore data structures. There are also functions for XML-RPC support; see below for details and see the XmlRpcClient Class for a class supporting communication with this protocol.

3.14.1. makeFormattedXMLFragment()

Synopsis

Serializes a hash into an XML string with formatting without an XML header.

Prototype

makeFormattedXMLFragment(hash $data, string $encoding) returns string

makeFormattedXMLFragment(hash $data) returns string

makeFormattedXMLFragment() returns nothing (RT_NOOP)

Example
$xml = makeFormattedXMLFragment($hash);

Table 3.420. Arguments and Return Values for makeFormattedXMLFragment()

Argument Type

Return Type

Description

hash $data, [string $encoding]

string

Serializes the Qore hash to an XML string (see XML Integration for more information) without an XML header but with formatting. The hash must have only one top-level key or an exception will be thrown. The optional second argument can give the output string encoding, otherwise UTF-8 is used (not the default encoding for the process).


Table 3.421. Exceptions Thrown by makeFormattedXMLFragment()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.2. makeFormattedXMLRPCCallString()

Synopsis

Serializes the arguments into an XML string in XML-RPC call format with whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCCallString(string $method, ...) returns string

Example
$xml = makeFormattedXMLRPCCallString("method.name", $arg1, $arg2);

Table 3.422. Arguments and Return Values for makeFormattedXMLRPCCallString()

Argument Type

Return Type

Description

string $method, ...

string

Serializes the arguments into an XML string in XML-RPC call format with whitespace formatting. The encoding of the resulting string will always be the default encoding.


Table 3.423. Exceptions Thrown by makeFormattedXMLRPCCallString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.3. makeFormattedXMLRPCCallStringWithEncoding()

Synopsis

Serializes the arguments into an XML string for an XML-RPC call with whitespace formatting, taking an initial string argument to give the encoding for the created XML.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCCallStringWithEncoding(string $encoding, string $method, ...) returns string

Example
$xml = makeFormattedXMLRPCCallStringWithEncoding("ISO-8859-1", "method.name", $arg1, $arg2);

Table 3.424. Arguments and Return Values for makeFormattedXMLRPCCallStringWithEncoding()

Argument Type

Return Type

Description

string $encoding, string $method, ...

string

Serializes the arguments into an XML string in XML-RPC call format with whitespace formatting. The encoding of the resulting string is given by the first argument.


Table 3.425. Exceptions Thrown by makeFormattedXMLRPCCallStringWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.4. makeFormattedXMLRPCCallStringArgs()

Synopsis

Serializes the arguments into an XML string in XML-RPC call format with whitespace formatting, taking a single argument following the XML-RPC method name for the argument list to the method.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCCallStringArgs(string $method, any $args) returns string

Example
$xml = makeFormattedXMLRPCCallStringArgs("method.name", $arg_list);

Table 3.426. Arguments and Return Values for makeFormattedXMLCallStringArgs()

Argument Type

Return Type

Description

string $method, list or any $args

string

Serializes the arguments into an XML string in XML-RPC call format with whitespace formatting, using a single argument following the XML-RPC method name as the argument list for the method. The encoding of the resulting string will always be the default encoding.


Table 3.427. Exceptions Thrown by makeFormattedXMLRPCCallStringArgs()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.5. makeFormattedXMLRPCCallStringArgsWithEncoding()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC call with whitespace formatting, taking an initial string argument to give the encoding for the created XML, followed by the method name, followed by a single list argument for the argument list.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCCallStringArgsWithEncoding(string $encoding, string $method, any $args) returns string

Example
$xml = makeFormattedXMLRPCCallStringArgsWithEncoding("ISO-8859-1", "method.name", $arg_list);

Table 3.428. Arguments and Return Values for makeFormattedXMLRPCCallStringArgsWithEncoding()

Argument Type

Return Type

Description

string $encoding, string $method, list or any $args

string

Serializes the arguments into an XML string in XML-RPC call format with whitespace formatting, using a single argument following the XML-RPC method name as the argument list for the method. The encoding of the resulting string will be the encoding given by the first argument.


Table 3.429. Exceptions Thrown by makeFormattedXMLRPCCallStringArgsWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.6. makeFormattedXMLRPCFaultResponseString()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC fault response with whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCFaultResponseString(any $code, string $msg) returns string

Example
$xml = makeFormattedXMLRPCFaultResponseString(10, "oh no, big error");

Table 3.430. Arguments and Return Values for makeFormattedXMLRPCFaultResponseString()

Argument Type

Return Type

Description

any $code, string $msg

string

Serializes the arguments into an XML string formatted for an XML-RPC fault response with whitespace formatting. The first argument is converted to an integer to give the XML-RPC error code. The encoding of the resulting string will always be the default encoding.


Table 3.431. Exceptions Thrown by makeFormattedXMLRPCCallStringArgs()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.

MAKE-XMLRPC-FAULT-RESPONSE-STRING-PARAMETER-ERROR

missing either the error code or the error string arguments.


3.14.7. makeFormattedXMLRPCFaultResponseStringWithEncoding()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC fault response with whitespace formatting, taking an initial string argument to give the encoding for the created XML.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCFaultResponseStringWithEncoding(string $encoding, any $code, string $msg) returns string

Example
$xml = makeFormattedXMLRPCFaultResponseStringWithEncoding("ISO-8859-2", 10, "oh no, big error");

Table 3.432. Arguments and Return Values for makeFormattedXMLRPCFaultResponseStringWithEncoding()

Argument Type

Return Type

Description

string $encoding, any $code, string $msg

string

Serializes the arguments into an XML string formatted for an XML-RPC fault response with whitespace formatting. The first argument give the XML-RPC fault code. The encoding of the resulting string will be the encoding given by the first argument.


Table 3.433. Exceptions Thrown by makeFormattedXMLRPCCallStringArgsWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.

MAKE-XMLRPC-FAULT-RESPONSE-STRING-PARAMETER-ERROR

missing either the error code or the error string arguments.


3.14.8. makeFormattedXMLRPCResponseString()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC response with whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCResponseString(...) returns any

Example
$xml = makeFormattedXMLRPCResponseString($value);

Table 3.434. Arguments and Return Values for makeFormattedXMLRPCResponseString()

Argument Type

Return Type

Description

...

string

Serializes the arguments into an XML string formatted for an XML-RPC response with whitespace formatting>. The encoding of the resulting string will always be the default encoding.


Table 3.435. Exceptions Thrown by makeFormattedXMLRPCResponseString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.9. makeFormattedXMLRPCResponseStringWithEncoding()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC response with whitespace formatting, taking an initial string argument to give the encoding for the created XML.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCResponseStringWithEncoding(string $encoding, ...) returns any

Example
$xml = makeFormattedXMLRPCResponseStringWithEncoding("ISO-8859-1", $value);

Table 3.436. Arguments and Return Values for makeFormattedXMLRPCResponseStringWithEncoding()

Argument Type

Return Type

Description

string $encoding, ...

string

Serializes the arguments into an XML string formatted for an XML-RPC response with whitespace formatting>. The encoding of the resulting string is given by the first argument.


Table 3.437. Exceptions Thrown by makeFormattedXMLRPCResponseStringWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.10. makeFormattedXMLRPCValueString()

Synopsis

Serializes the arguments into an XML string in XML-RPC value format with whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeFormattedXMLRPCValueString(any $data, string $encoding) returns string

makeFormattedXMLRPCValueString(any $data) returns string

Example
$xml = makeFormattedXMLRPCValueString($value);

Table 3.438. Arguments and Return Values for makeFormattedXMLRPCValueString()

Argument Type

Return Type

Description

any $data, [string $encoding]

string

Serializes the arguments into an XML string in XML-RPC value format with whitespace formatting. The optional second argument may be given to set the output string encoding, otherwise the encoding of the resulting string will be the default encoding.


Table 3.439. Exceptions Thrown by makeFormattedXMLRPCValueString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.11. makeFormattedXMLString()

Synopsis

Serializes a hash into an XML string with formatting and an XML header.

Prototype

makeFormattedXMLString(hash $data) returns string

makeFormattedXMLString(hash $data, string $encoding) returns string

makeFormattedXMLString(string $top_element, hash $data) returns string

makeFormattedXMLString(string, hash $data, string) returns string $encoding

Examples
$xml = makeFormattedXMLString($hash);
$xml = makeFormattedXMLString("key", $hash);

Table 3.440. Arguments and Return Values for makeFormattedXMLString()

Argument Type

Return Type

Description

hash $data, [string $encoding]

string

Serializes the Qore hash to an XML string (see XML Integration for more information) with an XML header and formatting. The hash must have only one top-level key or an exception will be thrown. The optional second argument may be given to specify the output string encoding, otherwise UTF-8 will be used.

string $top_element, hash $data, [string $encoding]

string

Serializes the Qore hash to an XML string (see XML Integration for more information) with an XML header and formatting. The first parameter will be the top-level XML element. The optional third argument may be given to specify the output string encoding, otherwise UTF-8 will be used.


Table 3.441. Exceptions Thrown by makeFormattedXMLString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.

MAKE-FORMATTED-XML-STRING-PARAMETER-EXCEPTION

Incorrect arguments passed.


3.14.12. makeXMLFragment()

Synopsis

Serializes a hash into an XML string without whitespace formatting and without an XML header.

Prototype

makeXMLFragment(hash $data, string $encoding) returns string

makeXMLFragment(hash $data) returns string

makeXMLFragment() returns nothing (RT_NOOP)

Example
$xml = makeXMLFragment($hash);

Table 3.442. Arguments and Return Values for makeXMLFragment()

Argument Type

Return Type

Description

hash $data, [string $encoding]

string

Serializes the Qore hash to an XML string (see XML Integration for more information) without an XML header and without whitespace formatting. The hash must have only one top-level key or an exception will be thrown. The optional second argument can give the output string encoding, otherwise the default encoding is used.


Table 3.443. Exceptions Thrown by makeXMLFragment()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.13. makeXMLRPCCallString()

Synopsis

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCCallString(string $method, ...) returns string

Example
$xml = makeXMLRPCCallString("method.name", $arg1, $arg2);

Table 3.444. Arguments and Return Values for makeXMLRPCCallString()

Argument Type

Return Type

Description

string $method, ...

string

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting. The encoding of the resulting string will always be the default encoding.


Table 3.445. Exceptions Thrown by makeXMLRPCCallString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.14. makeXMLRPCCallStringWithEncoding()

Synopsis

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting, taking an initial string argument to give the target character encoding for the XML string.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCCallStringWithEncoding(string $encoding, string $method, ...) returns string

Example
$xml = makeXMLRPCCallStringWithEncoding("ISO-8859-2", "method.name", $arg1, $arg2);

Table 3.446. Arguments and Return Values for makeXMLRPCCallStringWithEncoding()

Argument Type

Return Type

Description

string $encoding, string $method, ...

string

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting. The encoding of the resulting string will correspond to the encoding given as the first argument.


Table 3.447. Exceptions Thrown by makeXMLRPCCallStringWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.15. makeXMLRPCCallStringArgs()

Synopsis

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting, taking a single argument following the XML-RPC method name for the argument list to the method.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCCallStringArgs(string $method, any $args) returns string

Example
$xml = makeXMLRPCCallStringArgs("method.name", $arg_list);

Table 3.448. Arguments and Return Values for makeXMLCallStringArgs()

Argument Type

Return Type

Description

string $method, list or any $args

string

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting, using a single argument following the XML-RPC method name as the argument list for the method. The encoding of the resulting string will always be the default encoding.


Table 3.449. Exceptions Thrown by makeXMLRPCCallStringArgs()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.16. makeXMLRPCCallStringArgsWithEncoding()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC call without whitespace formatting, taking an initial string argument to give the target character encoding for the XML string followed by a list argument for the argument list.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCCallStringArgsWithEncoding(string $encoding, string $method, any $args) returns string

Example
$xml = makeXMLRPCCallStringArgsWithEncoding("ISO-8859-2", "method.name", $arg_list);

Table 3.450. Arguments and Return Values for makeXMLCallStringArgsWithEncoding()

Argument Type

Return Type

Description

string $encoding, string $method>, list or any $args

string

Serializes the arguments into an XML string in XML-RPC call format without whitespace formatting, using a single argument following the XML-RPC method name as the argument list for the method. The encoding of the resulting string will correspond to the encoding given as the first argument to the function.


Table 3.451. Exceptions Thrown by makeXMLRPCCallStringArgsWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.17. makeXMLRPCFaultResponseString()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC fault response without whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCFaultResponseString(any $code, string $msg) returns string

Example
$xml = makeXMLRPCFaultResponseString(10, "oh no, an error occured");

Table 3.452. Arguments and Return Values for makeXMLRPCFaultResponseString()

Argument Type

Return Type

Description

any $code, string $msg

string

Serializes the arguments into an XML string formatted for an XML-RPC fault response without whitespace formatting. The encoding of the resulting string will always be the encoding of the fault string (2nd argument).


Table 3.453. Exceptions Thrown by makeXMLRPCFaultResponseString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.

MAKE-XMLRPC-FAULT-RESPONSE-STRING-PARAMETER-ERROR

missing either the error code or the error string arguments.


3.14.18. makeXMLRPCFaultResponseStringWithEncoding()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC fault response without whitespace formatting, taking an initial string argument to give the target character encoding for the XML string.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCFaultResponseStringWithEncoding(string $encoding, any $code, string $msg) returns string

Example
$xml = makeXMLRPCFaultResponseStringWithEncoding("ISO-8859-2", 10, "oh no, an error occured");

Table 3.454. Arguments and Return Values for makeXMLRPCFaultResponseStringWithEncoding()

Argument Type

Return Type

Description

string $encoding, any $code, string $msg

string

Serializes the arguments into an XML string formatted for an XML-RPC fault response without whitespace formatting. The encoding of the resulting string will correspond to the encoding given as the first argument.


Table 3.455. Exceptions Thrown by makeXMLRPCFaultResponseStringWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.

MAKE-XMLRPC-FAULT-RESPONSE-STRING-PARAMETER-ERROR

missing either the error code or the error string arguments.


3.14.19. makeXMLRPCResponseString()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC response without whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCResponseString(...) returns any

Example
$xml = makeXMLRPCResponseString($response);

Table 3.456. Arguments and Return Values for makeXMLRPCResponseString()

Argument Type

Return Type

Description

...

string

Serializes the arguments into an XML string formatted for an XML-RPC response without whitespace formatting>. The encoding of the resulting string will always be the default encoding.


Table 3.457. Exceptions Thrown by makeXMLRPCResponseString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.20. makeXMLRPCResponseStringWithEncoding()

Synopsis

Serializes the arguments into an XML string formatted for an XML-RPC response without whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCResponseStringWithEncoding(string $encoding, ...) returns any

Example
$xml = makeXMLRPCResponseStringWithEncoding("ISO-8859-2", $response);

Table 3.458. Arguments and Return Values for makeXMLRPCResponseStringWithEncoding()

Argument Type

Return Type

Description

string $encoding, ...

string

Serializes the arguments into an XML string formatted for an XML-RPC response without whitespace formatting>. The encoding of the resulting string will correspond to the first argument.


Table 3.459. Exceptions Thrown by makeXMLRPCResponseStringWithEncoding()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.21. makeXMLRPCValueString()

Synopsis

Serializes the arguments into an XML string in XML-RPC value format without whitespace formatting.

For information about XML-RPC serialization, see XML-RPC Serialization.

Prototype

makeXMLRPCValueString(any, $data string $encoding) returns string

makeXMLRPCValueString(any $data) returns string

Example
$xml = makeXMLRPCValueString($value);

Table 3.460. Arguments and Return Values for makeXMLRPCValueString()

Argument Type

Return Type

Description

any $data, [string $encoding]

string

Serializes the arguments into an XML string in XML-RPC value format without whitespace formatting. The encoding of the resulting string will always be the default encoding.


Table 3.461. Exceptions Thrown by makeXMLRPCValueString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.


3.14.22. makeXMLString()

Synopsis

Serializes a hash into an XML string without whitespace formatting but with an XML header.

Prototype

makeXMLString(hash $data) returns string

makeXMLString(hash $data, string $encoding) returns string

makeXMLString(string $top_element, hash $data) returns string

makeXMLString(string, hash $data, string) returns string $encoding

Examples
$xml = makeXMLString($hash);
$xml = makeXMLString("key", $hash);

Table 3.462. Arguments and Return Values for makeXMLString()

Argument Type

Return Type

Description

hash $data, [string $encoding]

string

Serializes the Qore hash to an XML string (see XML Integration for more information) with an XML header but without whitespace formatting. The hash must have only one top-level key or an exception will be thrown. The optional second argument may be given to specify the output string encoding, otherwise UTF-8 will be used.

string $top_element, hash $data, [string $encoding]

string

Serializes the Qore hash to an XML string (see XML Integration for more information) with an XML header but without whitespace formatting. The first parameter will be the top-level XML element. The optional third argument may be given to specify the output string encoding, otherwise UTF-8 will be used.


Table 3.463. Exceptions Thrown by makeXMLString()

err

desc

MAKE-XML-ERROR

An error occurred serializing the Qore data to an XML string.

MAKE-XML-STRING-PARAMETER-EXCEPTION

Incorrect arguments passed.


3.14.23. parseXML()

Synopsis

Parses an XML string and returns a Qore hash structure. If duplicate, out-of-order XML elements are found in the input string, they are deserialized to Qore hash elements with the same name as the XML element but including a caret "^" and a numeric prefix to maintain the same key order in the Qore hash as in the input XML string.

This function should only be used when it is important to maintain the XML element order in the resulting Qore data structure (for example, when the data must be re-serialized to an XML string and the element order within a subelement must be maintained), for example, when parsing and reserializing an OSX property list in XML format. Otherwise parseXMLAsData() should be used instead.

Prototype

parseXML(string $xml_string) returns hash

parseXML(string $xml_string, string $encoding) returns hash

parseXML() returns nothing (RT_NOOP)

Example
$hash = parseXML($xml);

Table 3.464. Arguments and Return Values for parseXML()

Argument Type

Return Type

Description

string $xml_string, [string $encoding]

hash

Parses an XML string and returns a Qore hash structure. If no second argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.465. Exceptions Thrown by parseXML()

err

desc

PARSE-XML-EXCEPTION

Error parsing the XML string.


3.14.24. parseXMLAsData()

Synopsis

Parses an XML string as data (does not preserve hash order with out-of-order duplicate keys: collapses all to the same list) and returns a Qore hash structure.

Note that data deserialized with this function may not be reserialized to an identical XML string to the input due to the fact that duplicate, out-of-order XML elements are collapsed into lists in the resulting Qore hash, thereby losing the order in the original XML string.

For a similar function preserving the order of keys in the XML in the resulting Qore hash by generating Qore hash element names with numeric suffixes, see parseXML().

Prototype

parseXMLAsData(string $xml_string) returns hash

parseXMLAsData(string $xml_string, string $encoding) returns hash

parseXMLAsData() returns nothing (RT_NOOP)

Example
$hash = parseXMLAsData($xml);

Table 3.466. Arguments and Return Values for parseXMLAsData()

Argument Type

Return Type

Description

string $xml_string, [string $encoding]

hash

Parses an XML string and returns a Qore hash structure. If no second argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.467. Exceptions Thrown by parseXMLAsData()

err

desc

PARSE-XML-EXCEPTION

Error parsing the XML string.


3.14.25. parseXMLAsDataWithRelaxNG()

Synopsis

Parses an XML string as data (does not preserve hash order with out-of-order duplicate keys: collapses all to the same list), validates the XML string against a RelaxNG schema string, and returns a Qore hash structure. If any errors occur parsing the RelaxNG schema string, parsing the XML string, or validating the XML against the XSD, exceptions are thrown. If no encoding string argument is passed, then all strings in the resulting hash will be in UTF-8 encoding regardless of the input encoding of the XML string.

Please note that data deserialized with this function may not be reserialized to an identical XML string to the input due to the fact that duplicate, out-of-order XML elements are collapsed into lists in the resulting Qore hash, thereby losing the order in the original XML string.

For a similar function preserving the order of keys in the XML in the resulting Qore hash by generating Qore hash element names with numeric suffixes, see parseXMLWithRelaxNG(). See also parseXMLAsDataWithSchema() and parseXMLWithSchema().

The availability of this function depends on the presence of libxml2's xmlTextReaderRelaxNGSetSchema() function when Qore was compiled; for maximum portability check the constant HAVE_PARSEXMLWITHRELAXNG before running this function. See Library Option Constants for a list of all option constants.

Prototype

parseXMLAsDataWithRelaxNG(string $xml_string, string $relaxng_string) returns hash

parseXMLAsDataWithRelaxNG(string $xml_string, string $relaxng_string, string $encoding) returns hash

Example
$hash = parseXMLAsDataWithRelaxNG($xml, $rng);

Table 3.468. Arguments and Return Values for parseXMLAsDataWithRelaxNG()

Argument Type

Return Type

Description

string $xml_string, string $relaxng_string, [string $encoding]

hash

Parses an XML string (1st argument), validates against the RelaxNG string (2nd argument), and returns a Qore hash structure. If no third argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.469. Exceptions Thrown by parseXMLAsDataWithRelaxNG()

err

desc

PARSE-XML-EXCEPTION

Error parsing the XML string.

PARSE-XML-AS-DATA-WITH-RELAXNG-ERROR

Invalid arguments passed to the function.

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_PARSEXMLWITHRELAXNG before calling this function.


3.14.26. parseXMLAsDataWithSchema()

Synopsis

Parses an XML string as data (does not preserve hash order with out-of-order duplicate keys: collapses all to the same list), validates the XML string against an XSD schema string, and returns a Qore hash structure. If any errors occur parsing the XSD string, parsing the XML string, or validating the XML against the XSD, exceptions are thrown. If no encoding string argument is passed, then all strings in the resulting hash will be in UTF-8 encoding regardless of the input encoding of the XML string.

Please note that data deserialized with this function may not be reserialized to an identical XML string to the input due to the fact that duplicate, out-of-order XML elements are collapsed into lists in the resulting Qore hash, thereby losing the order in the original XML string.

For a similar function preserving the order of keys in the XML in the resulting Qore hash by generating Qore hash element names with numeric suffixes, see parseXMLWithSchema(). See also parseXMLAsDataWithRelaxNG() and parseXMLWithRelaxNG().

The availability of this function depends on the presence of libxml2's xmlTextReaderSetSchema() function when Qore was compiled; for maximum portability check the constant HAVE_PARSEXMLWITHSCHEMA before running this function. See Library Option Constants for a list of all option constants.

Prototype

parseXMLAsDataWithSchema(string $xml_string, string $xsd) returns hash

parseXMLAsDataWithSchema(string $xml_string, string $xsd, string $encoding) returns hash

Example
$hash = parseXMLAsDataWithSchema($xml, $xsd);

Table 3.470. Arguments and Return Values for parseXMLAsDataWithSchema()

Argument Type

Return Type

Description

string $xml_string, string $xsd, [string $encoding]

hash

Parses an XML string (1st argument), validates against the XSD string (2nd argument), and returns a Qore hash structure. If no third argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.471. Exceptions Thrown by parseXMLAsDataWithSchema()

err

desc

PARSE-XML-EXCEPTION

Error parsing the XML string.

PARSE-XML-WITH-SCHEMA-ERROR

Invalid arguments passed to the function.

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_PARSEXMLWITHSCHEMA before calling this function.


3.14.27. parseXMLRPCCall()

Synopsis

Deserializies an XML-RPC call string, returning a Qore data structure representing the call information.

Prototype

parseXMLRPCCall(string $xml_string) returns hash

parseXMLRPCCall(string $xml_string, string $encoding) returns hash

parseXMLRPCCall() returns nothing (RT_NOOP)

Example
$hash = parseXMLRPCCall($xml);

Table 3.472. Arguments and Return Values for parseXMLRPCCall()

Argument Type

Return Type

Description

string $xml_string, [string $encoding]

hash

Deserializies an XML-RPC call string, returning a Qore data structure representing the call information. The hash will have the following keys: methodName, params. If no second argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.473. Exceptions Thrown by parseXMLRPCCall()

err

desc

PARSE-XMLRPC-CALL-ERROR

Error parsing the XML-RPC call string.

PARSE-XMLRPC-VALUE-ERROR

Error parsing an XML-RPC value node.


3.14.28. parseXMLRPCResponse()

Synopsis

Deserializies an XML-RPC response string, returning a Qore data structure representing the response information.

Prototype

parseXMLRPCResponse(string $xml_string) returns hash

parseXMLRPCResponse(string $xml_string, string $encoding) returns hash

parseXMLRPCResponse() returns nothing (RT_NOOP)

Example
$hash = parseXMLRPCResponse($xml);

Table 3.474. Arguments and Return Values for parseXMLRPCResponse()

Argument Type

Return Type

Description

string $xml_string, [string $encoding]

hash

Deserializies an XML-RPC response string, returning a Qore data structure representing the response information. The hash will have either a "fault" or a "params" key, depending on if it's a fault response or a non-fault response. If no second argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.475. Exceptions Thrown by parseXMLRPCResponse()

err

desc

PARSE-XMLRPC-RESPONSE-ERROR

Error parsing the XML-RPC response string.

PARSE-XMLRPC-VALUE-ERROR

Error parsing an XML-RPC value node.


3.14.29. parseXMLRPCValue()

Synopsis

Deserializies an XML-RPC value tree, returning a Qore data structure representing the information.

Prototype

parseXMLRPCValue(string $xml_string) returns hash

parseXMLRPCValue(string $xml_string, string $encoding) returns hash

parseXMLRPCValue() returns nothing (RT_NOOP)

Example
my any $data = parseXMLRPCValue($xml);

Table 3.476. Arguments and Return Values for parseXMLRPCValue()

Argument Type

Return Type

Description

string $xml_string, [string $encoding]

any

Deserializies an XML-RPC value string, returning Qore data representing the value data. If no second argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.477. Exceptions Thrown by parseXMLRPCValue()

err

desc

PARSE-XMLRPC-VALUE-ERROR

Error parsing an XML-RPC value node.


3.14.30. parseXMLWithRelaxNG()

Synopsis

Parses an XML string, validates the XML string against a RelaxNG schema string, and returns a Qore hash structure. If any errors occur parsing the RelaxNG string, parsing the XML string, or validating the XML against the RelaxNG schema, exceptions are thrown. If no encoding string argument is passed, then all strings in the resulting hash will be in UTF-8 encoding regardless of the input encoding of the XML string.

If duplicate, out-of-order XML elements are found in the input string, they are deserialized to Qore hash elements with the same name as the XML element but including a caret "^" and a numeric prefix to maintain the same key order in the Qore hash as in the input XML string.

This function should only be used when it is important to maintain the XML element order in the resulting Qore data structure (for example, when the data must be re-serialized to an XML string and the element order within a subelement must be maintained), for example, when parsing and reserializing an OSX property list in XML format. Otherwise parseXMLAsDataWithRelaxNG() should be used instead.

See also parseXMLWithSchema() and parseXMLAsDataWithSchema().

The availability of this function depends on the presence of libxml2's xmlTextReaderRelaxNGSetSchema() function when Qore was compiled; for maximum portability check the constant HAVE_PARSEXMLWITHRELAXNG before running this function. See Library Option Constants for a list of all option constants.

Prototype

parseXMLWithRelaxNG(string $xml_string, string $relaxng_string) returns hash

parseXMLWithRelaxNG(string $xml_string, string $relaxng_string, string $encoding) returns hash

Example
$hash = parseXMLWithRelaxNG($xml, $rng);

Table 3.478. Arguments and Return Values for parseXMLWithRelaxNG()

Argument Type

Return Type

Description

string $xml_string, string $relaxng_string, [string $encoding]

hash

Parses an XML string (1st argument), validates against the RelaxNG schema string (2nd argument), and returns a Qore hash structure. If no third argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.479. Exceptions Thrown by parseXMLWithRelaxNG()

err

desc

PARSE-XML-EXCEPTION

Error parsing the XML string.

PARSE-XML-WITH-RELAXNG-ERROR

Invalid arguments passed to the function.

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_PARSEXMLWITHRELAXNG before calling this function.


3.14.31. parseXMLWithSchema()

Synopsis

Parses an XML string, validates the XML string against an XSD schema string, and returns a Qore hash structure. If any errors occur parsing the XSD string, parsing the XML string, or validating the XML against the XSD, exceptions are thrown. If no encoding string argument is passed, then all strings in the resulting hash will be in UTF-8 encoding regardless of the input encoding of the XML string.

If duplicate, out-of-order XML elements are found in the input string, they are deserialized to Qore hash elements with the same name as the XML element but including a caret "^" and a numeric prefix to maintain the same key order in the Qore hash as in the input XML string.

This function should only be used when it is important to maintain the XML element order in the resulting Qore data structure (for example, when the data must be re-serialized to an XML string and the element order within a subelement must be maintained), for example, when parsing and reserializing an OSX property list in XML format. Otherwise parseXMLAsDataWithSchema() should be used instead.

See also parseXMLWithRelaxNG() and parseXMLAsDataWithRelaxNG().

The availability of this function depends on the presence of libxml2's xmlTextReaderSetSchema() function when Qore was compiled; for maximum portability check the constant HAVE_PARSEXMLWITHSCHEMA before running this function. See Library Option Constants for a list of all option constants.

Prototype

parseXMLWithSchema(string $xml_string, string $xsd) returns hash

parseXMLWithSchema(string $xml_string, string $xsd, string $encoding) returns hash

Example
$hash = parseXMLWithSchema($xml, $xsd);

Table 3.480. Arguments and Return Values for parseXMLWithSchema()

Argument Type

Return Type

Description

string $xml_string, string $xsd, [string $encoding]

hash

Parses an XML string (1st argument), validates against the XSD string (2nd argument), and returns a Qore hash structure. If no third argument is given, specifying the output string encoding, all strings will have the default encoding.


Table 3.481. Exceptions Thrown by parseXMLWithSchema()

err

desc

PARSE-XML-EXCEPTION

Error parsing the XML string.

PARSE-XML-WITH-SCHEMA-ERROR

Invalid arguments passed to the function.

MISSING-FEATURE-ERROR

This exception is thrown when the function is not available; for maximum portability, check the constant HAVE_PARSEXMLWITHSCHEMA before calling this function.