/** @mainpage Qore XML Module @tableofcontents @section xmlintro Introduction XML functionality in the %Qore xml module is provided by the libxml2 library, which provides a powerful, stable, clean, and thread-safe basis for XML integration in %Qore. XML provides a way to describe hierarchical data, and thanks to libxml2, the xml module allows for easy serialization and deserialization between XML strings and %Qore data structures. This module is released under a choice of two licenses: - LGPL 2.1 - MIT (see COPYING.MIT in the source distribution for more information) . The module is tagged as such in the module's header (meaning it can be loaded unconditionally regardless of how the %Qore library was initialized). To use the module in a %Qore script, use the \c %%requires directive as follows: @code %requires xml @endcode @note XML functionality was included in the main %Qore shared library until version 0.8.1, at which time the code was removed to make this module. Classes provided by this module: - @ref Qore::Xml::FileSaxIterator "FileSaxIterator": an iterator class for XML strings - @ref Qore::Xml::SaxIterator "SaxIterator": an iterator class for XML strings - @ref Qore::Xml::XmlDoc "XmlDoc": for analyzing and manipulating XML documents - @ref Qore::Xml::XmlNode "XmlNode": gives information about XML data in an XML document - @ref Qore::Xml::XmlReader "XmlReader": for parsing or iterating through the elements of an XML document Also included with the binary xml module: - WSDL user module - SalesforceSoapClient user module - SoapClient user module - SoapHandler user module - XmlRpcHandler user module @section optionconstants Module Option Constants The following constants give information about the availability of XML functionality (dependent on libxml2 features at compile time): XML Option Constants |!Name|!Type|!Description |@ref Qore::Xml::Option::HAVE_PARSEXMLWITHRELAXNG "HAVE_PARSEXMLWITHRELAXNG"|\c bool|Indicates if parse_xml_with_relaxng() and Qore::Xml::XmlReader::relaxNGValidate() are available |@ref Qore::Xml::Option::HAVE_PARSEXMLWITHSCHEMA "HAVE_PARSEXMLWITHSCHEMA"|\c bool|Indicates if parse_xml_with_schema() and Qore::Xml::XmlReader::schemaValidate() are available If either of the above constants are \c False, then calling any of the dependent functions or methods will result in a run-time exception. @section serialization Automatic XML Serialization and Deserialization This section describes automatic XML serialization and deserialization; for iterative or user-controlled XML parsing, see @ref xmlclasses "XML Classes". XML serialization (conversion from %Qore data structures to XML strings) in the xml module relies on the fact that %Qore hashes retain insertion order, which means that conversion to and from %Qore data structures and XML strings can be done without data loss and without reordering the XML elements. In general, XML serialization is relatively straighforward, but there are a few issues to be aware of, particularly regarding element attributes and lists. These issues are described in the following paragraphs. First, a straightforward example: @code $h = ("record": ("name": ("first": "Fred", "last": "Smith"))); printf("%s\n", make_xml($h, XGF_ADD_FORMATTING));@endcode This produces the following result @verbatim Fred Smith @endverbatim To set XML attributes, the %Qore value must be a hash and the attributes are stored in another hash in the key \c "^attributes^". That is; the value of the \c "^attributes^" key must be a hash, and each member of this hash will represent an attribute-value pair. For example: @code $h = ("record": ("^attributes^": ("type": "customer") , "name": ("first": "Fred", "last": "Smith"))); printf("%s\n", make_xml($h, XGF_ADD_FORMATTING));@endcode This produces the following results: @verbatim Fred Smith @endverbatim If instead we wanted to have text instead of child data under the "record" node, we must set the \c "^value^" key of the hash along with the \c "^attributes^" key as follows: @code $h = ("record": ("^attributes^": ("type": "customer"), "^value^": "NO-RECORD")); printf("%s\n", make_xml($h, XGF_ADD_FORMATTING)); @endcode Giving the following results: @verbatim NO-RECORD@endverbatim Arrays are serialized with repeating node names as follows: @code $h = ("record": ("part": ("part-02-05", "part-99-23", "part-34-28"))); printf("%s\n", make_xml($h, XGF_ADD_FORMATTING));@endcode Producing the following results: @verbatim part-02-05 part-99-23 part-34-28 @endverbatim It gets a little trickier when a key should repeated at the same level in an XML string, but other keys come between, for example, take the following XML string: @verbatim Keywords: this, that, and the_other.@endverbatim It's not possible to use a list, because text is required in between. As described earlier, the \c "^value^" hash key can be used to serialize text in an XML string. In this case, we need to have several text nodes and several code nodes in a mixed-up order to give us the XML string we want. Because qore hases have unique keys (we can't use the same key twice in the same hash), we resort to a key naming trick that allows us to virtually duplicate our key names and therefore arrive at the XML string we want. We do this by appending a \c '^' character to the end of the key name and then some unique text. When serializing hash keys, any text after (and including) the \c '^' character is ignored. For the special key name \c "^value^", we do not need to duplicate the final \c '^' character. Instead we just add unique text to ensure that our hash can contain all the data we want and that it will be serialized in the right order to the XML string as follows: @code $h = ("para": ("^value^": "Keywords: ", "code" : "this", "^value^1" : ", ", "code^1" : "that", "^value^2" : ", and ", "code^2" : "the_other", "^value^3" : ".")); printf("%s\n", make_xml($h, XGF_ADD_FORMATTING));@endcode By ignoring the text after the \c '^' character, the above code will serialize to the XML string we want. In general, by using this convention, we can properly serialize multiple out-of-order keys without losing data and still have unique names for our hash keys. Note than when deserializing XML strings to %Qore data structures, the above rules are applied in reverse. If any out-of-order duplicate keys are detected, %Qore will automatically generate unique hash key names based on the above rules only if the @ref Qore::Xml::XPF_PRESERVE_ORDER "XPF_PRESERVE_ORDER" flag is given with the parse_xml(), parse_xml_with_relaxng() or parse_xml_with_schema() function calls. Also note that \c CDATA text will be generated if a hash key starts with \c '^cdata'; such text will not be processed for escape code substitution. When deserializing XML strings to qore data structures, CDATA text will be placed unmodified under such a hash key as well. Functions For XML Serialization and Deserialization |!Function Name|!Description |make_xml_fragment()|Serializes a hash into an XML string without an XML header or formatting. |make_xml()|Serializes a hash into a complete XML string with an XML header |parse_xml()|parses an XML string and returns a %Qore hash structure. |parse_xml_with_relaxng()|parses an XML string and validates against a RelaxNG schema string and returns a %Qore hash structure. |parse_xml_with_schema()|parses an XML string and validates against an XSD schema string and returns a %Qore hash structure. Deprecated Functions For XML Serialization and Deserialization - @ref makeFormattedXMLFragment(): deprecated by make_xml_fragment() - @ref makeFormattedXMLString(): deprecated by make_xml() - @ref makeXMLFragment(): deprecated by make_xml_fragment() - @ref makeXMLString(): deprecated by make_xml() - @ref parseXML(): deprecated by parse_xml() - @ref parseXMLAsData(): deprecated by parse_xml() - @ref parseXMLAsDataWithRelaxNG(): deprecated by parse_xml_with_relaxng() - @ref parseXMLAsDataWithSchema(): deprecated by parse_xml_with_schema() - @ref parseXMLWithRelaxNG(): deprecated by parse_xml_with_relaxng() - @ref parseXMLWithSchema(): deprecated by parse_xml_with_schema() @anchor xmlclasses Classes Providing XML Functionality |!Class|!Description |@ref Qore::Xml::FileSaxIterator "FileSaxIterator"|An iterator class for file data |@ref Qore::Xml::SaxIterator "SaxIterator"|An iterator class for XML strings |@ref Qore::Xml::XmlDoc "XmlDoc"|For analyzing and manipulating XML documents |@ref Qore::Xml::XmlNode "XmlNode"|Gives information about XML data in an XML document |@ref Qore::Xml::XmlReader "XmlReader"|For parsing or iterating through the elements of an XML document @section XMLRPC XML-RPC XML-RPC is a lightweight but powerful XML over HTTP web service protocol. The xml module includes builtin support for this protocol as described here. You can find more information about XML-RPC, including specifications and examples at http://xmlrpc.org. Information about %Qore's XML-RPC serialization can be found below. XML-RPC Serialization in %Qore |!%Qore Type|!XML-RPC Type|!Description |\c string|\c string|direct conversion to UTF-8 string |\c integer|\c i4 or \c string|If the integer requires more than 32 bits to represent, then it is sent as a string |\c float|\c double|direct conversion |\c number|\c double|conversion to a double for serialization |\c boolean|\c boolean|direct conversion |\c date|\c iso8601|Absolute date/time values will convert to the default time zone for the calling context for the output string if necessary. Note that relative date/time values (durations) will be serialized with the same format as absolute date/time values. |\c binary|\c base64|direct conversion |\c list|\c array|direct conversion |\c hash|\c struct|direct conversion |all others|n/a|All other types will cause an \c XML-RPC-SERIALIZATION-ERROR to be raised. Classes Providing XML-RPC Functionality |!Class|!Description |Qore::Xml::XmlRpcClient|For communicating with XML-RPC servers Functions Providing XML-RPC Functionality |!Function Name|!Description |make_xmlrpc_call()|Serializes a hash into an XML string formatted for an XML-RPC call |make_xmlrpc_fault()|Serializes a hash into an XML string formatted for an XML-RPC fault response |make_xmlrpc_value()|Serializes a hash into an XML string in XML-RPC value format |make_xmlrpc_response()|Serializes a hash into an XML string formatted for an XML-RPC response |parse_xmlrpc_call()|deserializies an XML-RPC call string, returning a %Qore hash respresenting the call information. |parse_xmlrpc_response()|deserializies an XML-RPC response string, returning a %Qore hash respresenting the response information. |parse_xmlrpc_value()|deserializies an XML-RPC value tree, returning a %Qore hash respresenting the information. Deprecated Functions For XML-RPC Serialization and Deserialization - @ref makeFormattedXMLRPCCallString(): deprecated by make_xmlrpc_call() - @ref makeFormattedXMLRPCCallStringArgs(): deprecated by make_xmlrpc_call() - @ref makeFormattedXMLRPCCallStringArgsWithEncoding(): deprecated by make_xmlrpc_call() - @ref makeFormattedXMLRPCCallStringWithEncoding(): deprecated by make_xmlrpc_call() - @ref makeFormattedXMLRPCFaultResponseString(): deprecated by make_xmlrpc_fault() - @ref makeFormattedXMLRPCFaultResponseStringWithEncoding(): deprecated by make_xmlrpc_fault() - @ref makeFormattedXMLRPCResponseString(): deprecated by make_xmlrpc_response() - @ref makeFormattedXMLRPCResponseStringWithEncoding(): deprecated by make_xmlrpc_response() - @ref makeFormattedXMLRPCValueString(): deprecated by make_xmlrpc_value() - @ref makeXMLRPCCallString(): deprecated by make_xmlrpc_call() - @ref makeXMLRPCCallStringArgs(): deprecated by make_xmlrpc_call() - @ref makeXMLRPCCallStringArgsWithEncoding(): deprecated by make_xmlrpc_call() - @ref makeXMLRPCCallStringWithEncoding(): deprecated by make_xmlrpc_call() - @ref makeXMLRPCFaultResponseString(): deprecated by make_xmlrpc_fault() - @ref makeXMLRPCFaultResponseStringWithEncoding(): deprecated by make_xmlrpc_fault() - @ref makeXMLRPCResponseString(): deprecated by make_xmlrpc_response() - @ref makeXMLRPCResponseStringWithEncoding(): deprecated by make_xmlrpc_response() - @ref makeXMLRPCValueString(): deprecated by make_xmlrpc_value() - @ref parseXMLRPCCall(): deprecated by parse_xmlrpc_call() - @ref parseXMLRPCResponse(): deprecated by parse_xmlrpc_response() - @ref parseXMLRPCValue(): deprecated by parse_xmlrpc_value() @section constants XML Constants All constants (and classes and namespaces) provided by this module are created under the Qore namespace (the main namespace for the %Qore Programming Language). @section codetags Function and Method Tags @subsection NOOP NOOP Code with this flag makes no calculations, but rather returns a constant value. This flag is given to function and method variants that return a default value depending on the type of argument(s). When variants with this flag are resolved at parse time, a \c "call-with-type-errors" warning is raised (assuming this warning is enabled), unless \c PO_REQUIRE_TYPES or \c PO_STRICT_ARGS is set. If \c PO_REQUIRE_TYPES or \c PO_STRICT_ARGS is set, then these variants are inaccessible at parse time; resolving to a variant with this flag set at parse time causes an exception to be thrown. These variants are included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. This tag is equal to @ref RUNTIME_NOOP, except no runtime effect is caused by resolving a function or method tagged with \c NOOP at runtime; this tag only affects parse time resolution. @subsection RUNTIME_NOOP RUNTIME_NOOP Code with this flag makes no calculations, but rather returns a constant value. This flag is given to function and method variants that return a default value depending on the type of argument(s). When variants with this flag are resolved at parse time, a \c "call-with-type-errors" warning is raised (assuming this warning is enabled), unless \c PO_REQUIRE_TYPES or \c PO_STRICT_ARGS is set. If \c PO_REQUIRE_TYPES or \c PO_STRICT_ARGS is set, then these variants are inaccessible; resolving to a variant with this flag set at parse time or run time causes an exception to be thrown. These variants are included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. This tag is equal to @ref NOOP, except that \c RUNTIME_NOOP is also enforced at runtime. @subsection RET_VALUE_ONLY RET_VALUE_ONLY This flag indicates that the function or method has no side effects; it only returns a value, for example. This tag is identical to @ref CONSTANT except that functions or methods tagged with \c RET_VALUE_ONLY could throw exceptions. @subsection CONSTANT CONSTANT This flag indicates that the function or method has no side effects and does not throw any exceptions. This tag is identical to @ref RET_VALUE_ONLY except that functions or methods tagged with \c CONSTANT do not throw exceptions. @subsection DEPRECATED DEPRECATED Code with this flag is deprecated and may be removed in a future version of this module; if a variant with this flag is resolved at parse time, a \c "deprecated" warning is raised (assuming this warning is enabled). @section xmlreleasenotes Release Notes @subsection xml132 xml Module Version 1.3.2 Changes and Bug Fixes in This Release - fixed SOAP handler to produce correct URLs in WSDL (issue 1631) - added documentation for the WSOperation class in the WSDL module (issue 1670) - fixed \c SalesforceSoapClient::callOperation() in the SalesforceSoapClient module to respect the \c soapaction header (issue 1659) @subsection xml131 xml Module Version 1.3.1 Changes and Bug Fixes in This Release - fixed a memory leak in XML-RPC parsing (issue 1214) - WSDL fixes and enhancements: - supress emitting a SOAPAction header in requests if the binding gives an empty string (issue 1226) - updated \c WSOperation::serializeRequest() to allow the SOAPAction header to be overridden in each request (issue 1226) - respect XML generation flags in request generation - fixed parsing empty base64Binary and hexBinary elements (issue 1227) - SoapClient fixes and enhancements: - added the \c SoapClient::callOperation() method (issue 1226) - updated SOAP response processing to throw an exception when the server responds with an error code (issue 1228) - content-type in exceptional cases follows Soap version (issue 1244) - fixed a typo in a debug logging statement (issue 1358) - fixed and documented the "info" output hash format (issue 1359) - fixed a typo in a debug logging statement (issue 1358) - fixed and documented the "info" output hash format (issue 1359) - fixed a bug in the SoapClient::constructor() where a WebService object was not supported (issue 1424) - added SalesforceSoapClient user module - added Salesforce.com.qtest and accompanying WSDLs @subsection xml13 xml Module Version 1.3 Changes and Bug Fixes in This Release - added the @ref Qore::Xml::SaxIterator "SaxIterator" and @ref Qore::Xml::FileSaxIterator "FileSaxIterator" classes - WSDL fixes and enhancements: - many major SOAP messaging and WSDL handling fixes including major namespace handling and serialization/deserialization fixes - complexType attributes are now serialized and deserialized correctly - elements with the same names in different namespaces are now handled correctly - complexTypes wtih a sequence of choice and element elements are now handled correctly - allow for XSD imports without a URI scheme to be imported with custom logic - perform environment-variable substitution on the file path in WSDLLib::getWSDL() - better support for empty elements; correct de/serialization depending on element and type properties - allow for schema definitions to temporarily override namespace prefixes within that schema - implemented support for default namespace handling for base types - implemented support for operations with either a missing input or output message - XSD \c "integer" types are returned as integers when possible - fixed a bug in XSD namespace handling - fixed bugs deserializing xml nil elements (issue 468) - fixed a bug handling types with more than two levels of nested references (issue 560) - fixed namespace prefix generation with elements in different schemas and for elements based on references (issue 561) - new APIs for WebService introspection and WSDL retrieving (issue 571) - fixed a bug handling empty lists for optional elements (issue 663) - fixed a bug setting the \c "charset=..." value in HTTP headers (issue 906) - SoapClient fixes: - fixed URI request path - fixed agent string - added optional logging closures - added SOAP headers to info hash when available - fixed parsing messages with multiple input parts - required modules are now reexported - added the following methods: - SoapClient::addDefaultHeaders() - SoapClient::getDefaultHeaders() - SoapClient::getSendEncoding() - SoapClient::getWebService() - SoapClient::setContentEncoding() - SoapClient::setSendEncoding() - updated for new WebService APIs - SoapHandler changes: - allow SOAP serialization errors to be logged at the source - added support for matching requests by soap action values - allow \c "^header^" key in top-level hash response to specify SOAP headers in the response message - 500 HTTP response code returned with SOAP faults - added support for debugging (verbose exception info/logging) - updated for new WebService APIs; improved URL matching - improved service URL generation - WSDLs are now returned with the correct service URLs (issue 568, issue 571) - user modules moved to top-level qore module directory from version-specific module directory since they are valid for multiple versions of qore - implemented the following non-camel-case functions as replacements for old camel-case functions (the following camel-case function names are now deprecated): - make_xml(): replaced: - makeXMLString() - makeFormattedXMLString() - make_xml_fragment(): replaced: - makeXMLFragment() - makeFormattedXMLFragment() - make_xmlrpc_call(): replaced: - makeFormattedXMLRPCCallString() - makeFormattedXMLRPCCallStringArgs() - makeFormattedXMLRPCCallStringArgsWithEncoding() - makeFormattedXMLRPCCallStringWithEncoding() - makeXMLRPCCallString() - makeXMLRPCCallStringArgs() - makeXMLRPCCallStringArgsWithEncoding() - makeXMLRPCCallStringWithEncoding() - make_xmlrpc_fault(): replaced: - makeFormattedXMLRPCFaultResponseString() - makeFormattedXMLRPCFaultResponseStringWithEncoding() - makeXMLRPCFaultResponseString() - makeXMLRPCFaultResponseStringWithEncoding() - make_xmlrpc_response(): replaced: - makeFormattedXMLRPCResponseString() - makeFormattedXMLRPCResponseStringWithEncoding() - makeXMLRPCResponseString() - makeXMLRPCResponseStringWithEncoding() - make_xmlrpc_value(): replaced: - makeFormattedXMLRPCValueString() - makeXMLRPCValueString() - parse_xml(): replaced: - parseXML() - parseXMLAsData() - parse_xml_with_relaxng(): replaced: - parseXMLWithRelaxNG() - parseXMLAsDataWithRelaxNG() - parse_xml_with_schema(): replaced: - parseXMLWithSchema() - parseXMLAsDataWithSchema() - parse_xmlrpc_call(): replaced parseXMLRPCCall() - parse_xmlrpc_response(): replaced parseXMLRPCResponse() - parse_xmlrpc_value(): replaced: parseXMLRPCValue() - SOAP and WSDL test infrastructure @subsection xml12 xml Module Version 1.2 Changes and Bug Fixes in This Release - implemented dynamic unbinding of service methods in the SoapHandler module - fixed bugs in @ref Qore::Xml::XmlReader::toQore() "XmlReader::toQore()" and @ref Qore::Xml::XmlReader::toQoreData() "XmlReader::toQoreData()" for SAX parsing - implemented enhanced logging for the XmlRpcHandler module - doc updates @subsection xml11 xml Module Version 1.1 Changes and Bug Fixes in This Release - fixed internal XMl to Qore processing for extreme cases - fixed makeFormattedXMLString() to really format the output - fixed XML-RPC parsing with empty elements in structures - added additional validation to XML-RPC parsing (checking close elements) - set the character encoding correctly in the outgoing \c "Content-Type" request header - added suport for the new arbitrary-precision numeric type introduced with Qore 0.8.6 */