APPENDIX A ■ ■ ■ XML Schema Built-in Data Types Reference

XML Schemas provide a number of built-in data types. You can use these types directly as types or use them as base types to create new and complex data types. The built-in types presented in this appendix are broken down into primitive and derived types and further grouped by area of functionality for easier reference.

Type Definition XML Schema data types are built upon relationships where every type definition is either an extension or a restriction to another type definition. This relationship is called the type defi- nition hierarchy. The topmost definition, serving as the root of the hierarchy, is the ur-type definition, named anyType. It is the only definition that does not have a basis in any other type. Using this data type is similar to using ANY within a DTD. It effectively means that the data has no constraints. Take the following element declaration, for example:

An element based on this declaration can contain any type of data. It can be any of the built-in types as well as any user-derived type. The simple ur-type definition, named anySimpleType, is a special restriction on the ur-type definition. It constrains the anyType definition by limiting data to only the built-in data types, shown in the following sections. For example, the following element declaration defines an element that can be any built-in type but cannot be a complex type, which is sim- ply an element that can contain subelements or attributes, as explained in Chapter 3:

The built-in types are divided into two varieties: primitive types and derived types.

Primitive Types Primitive data types are those that are not defined in terms of another type. For easy reference, the following tables group the primitive types together based on general, non-schema-specific data types. Table A-1 shows the logical types, Table A-2 shows the numeric types, Table A-3 839

R. Richards, Pro PHP XML and Web Services, DOI 10.1007/978-1-4302-0139-7, © 2006 by Robert Richards 840 APPENDIX A ■ XML SCHEMA BUILT-IN DATA TYPES REFERENCE

shows the textual types, Table A-4 shows the date/time types, Table A-5 shows the binary types, and Table A-6 shows the XML types.

Table A-1. Logical Types Type Description Example boolean Represents the binary-valued logic literals true, false, 1, 0

Table A-2. Numeric Types Type Description Example decimal Arbitrary-precision decimal numbers. 1.0, 1.00, -1, 01.1230, 1.123 The sign is optional, and when omitted, + is assumed. double Real numbers with a double-precision, INF, -INF, NaN (Not a Number), 1.234, 1.2e3, 7E-10 64-bit, floating-point type. float Real numbers with a double-precision, INF, -INF, NaN (Not a Number), 1.234, 1.2e3, 7E-10 32-bit, floating-point type.

Table A-3. Textual Types Type Description Example string Any legal XML character string according This is a string, This & that are strings to the XML 1.0 specification. Special characters such as <, >, &, ', and " should be escaped. AnyURI A URI. It can be absolute or relative and http://www.example.com can contain a fragment identifier.

Table A-4. Date/Time Types Type Description Example dateTime A date and time in the format CCYY- October 31, 2005, at 2:30 p.m. Coordinated MM-DDTHH:MM:SS. Universal Time (UTC) time is written as 2005-10- 31T14:30:00. The same date and time written in Eastern Standard Time (EST) is 2005-10- 31T14:30:00-5:00. date A calendar date in the format CCYY- October 31, 2005, is written as 2005-10-31. MM-DD with an optional time zone. time An instance of time during a day in the So, 2:30 p.m. UTC time is 14:30:00; the same time format HH:MM:SS. written in EST is 140:30:00-5:00. duration A duration of time in the format A duration of 1 year, 2 months, 3 days, 10 hours, PnYnMnDTnHnMnS. If the number of and 30 minutes is written as P1Y2M3DT10H30M, years, months, days, hours, minutes, or while a duration of 1 year is written as P1Y. seconds in any expression is zero, the number and its corresponding designator can be omitted, but at least one designator and the P designator must always be present. APPENDIX A ■ XML SCHEMA BUILT-IN DATA TYPES REFERENCE 841

Type Description Example gMonth Two-digit Gregorian month in the October is written as —10, and April is written format —MM with an optional time zone. as —04. gDay Two-digit Gregorian day in the format The 22nd day of the month is written as —22. —DD with an optional time zone. gYear Four-digit Gregorian year in the format The year 2005 is written as 2005. CCYY with an optional time zone. gMonthDay Combination of the Gregorian month October 31 is written as —10-31. and day in the format —MM-DD with an optional time zone. gYearMonth Combination of the Gregorian year October 2005 is written as 2005-10. and month in the format CCYY-MM with an optional time zone.

Table A-5. Binary Types Type Description Example base64Binary Base64-encoded arbitrary binary data See base64_decode() in the PHP manual. hexBinary Arbitrary hex-encoded binary data See bin2hex() in the PHP manual.

Table A-6. XML Types Type Description Example QName Represents an XML qualified name. prefix:name, xsd:attribute NOTATION Represents an XML NOTATION attribute. This type must not be used in an XML Schema. You can use it only to derive types that can be used in an XML Schema.

Derived Types Derived types are data types that are defined in terms of other types, called base types. As you will see in the following tables, a base type for a derived type can be a primitive data type or even another derived type. These types also have been grouped into generalized, non-schema- specific data types. Table A-7 shows the numeric types, Table A-8 shows the textual types, and Table A-9 shows the XML types. 842 APPENDIX A ■ XML SCHEMA BUILT-IN DATA TYPES REFERENCE

Table A-7. Numeric Types Type Base Type Description Example integer decimal The mathematical concept of integer 1, 0, -1, 12345 numbers nonPositiveInteger integer Any integer less than or equal to 0 0, -1, -12345 negativeInteger nonPositiveInteger Any integer less than 0 -1, -12345, -23456 long integer Any integer less than or equal to -100000, 0, 9,223,372,036,854,775,807 and greater or 10000 equal to -9,223,372,036,854,775,808 int long Any integer less than or equal to -2147483648 2,147,483,647 and greater or equal to -2,147,483,648 short integer Any integer less than or equal to 32,767 12345, -12345 and greater or equal to -32,768 byte short Any integer less than or equal to 127 and -123, 0, 123 greater or equal to -128 nonNegativeInteger integer Any integer greater than or equal to 0 0, 1, 12345 positiveInteger nonNegativeInteger Any integer greater than 0 1, 12345, 123456 unsignedLong nonNegativeInteger Any integer greater than or equal to 0 and 0, 12345, less than or equal to 1234567 18,446,744,073,709,551,615 unsignedInt unsignedLong Any integer greater than or equal to 0 and 0, 12345, less than or equal to 4,294,967,295 1234567 unsignedShort unsignedInt Any integer greater than or equal to 0 and 0, 1234, 65535 less than or equal to 65,535 unsignedByte unsignedShort Any integer greater than or equal to 0 and 0, 100, 126 less than or equal to 255

Table A-8. Textual Types Type Base Type Description Example normalizedString string A whitespace-normalized string. This means it Example does not contain carriage returns, line feeds, or normalized tab characters. string token normalizedString A tokenized string. This means it does not A B C contain carriage returns, line feeds, or tab characters. It also does not have leading or trailing spaces, and any two consecutive characters in the string are spaces. language token Language identifiers as defined by RFC 3066 en-US (http://www.ietf.org/rfc/rfc3066.txt). APPENDIX A ■ XML SCHEMA BUILT-IN DATA TYPES REFERENCE 843

Table A-9. XML Types Type Base Type Description Example Name token Represents an XML name as defined in the XML 1.0 specification NCName Name Represents XML “noncolonized” names, which are simply element QNames without the prefix and colon ID NCName Represents the ID attribute type from the XML 1.0 specification IDREF NCName Represents the IDREF attribute type from the XML 1.0 specification IDREFS IDREF Represents the IDREFS attribute type from the XML 1.0 specification ENTITY NCName Represents the ENTITY attribute type from the XML 1.0 specification ENTITIES ENTITY Represents the ENTITIES attribute type from the XML 1.0 specification NMTOKEN token Represents the NMTOKEN attribute type from the XML 1.0 specification NMTOKENS NMTOKEN Represents the NMTOKENS attribute type from the XML 1.0 specification APPENDIX B ■ ■ ■ Extension APIs

This appendix is a quick reference for the XML parser extensions in PHP. You can find usage examples and more detailed information in each parser’s respective chapter. The information provided for the APIs covers functionality found in PHP 5.1.2, as well as a few new methods that will be released with PHP 6. libxml The libxml extension, described in Chapter 5, is the foundation for all the XML-based exten- sions in PHP. As of PHP 5.1, the extension defines common constants and functionality used by a majority of the other related extensions. Table B-1 lists the general constants. Note that some constants are defined only when using certain versions of the libxml2 library.

Table B-1. libxml General Constants Name Description LIBXML_VERSION The numeric value of the libxml2 version being used by PHP. You can use this value to test the version number for functionality that depends upon certain versions of libxml2. LIBXML_DOTTED_VERSION The string value using dotted notation of the libxml2 version being used. This value is primarily used for display purposes.

The extensions, such as DOM and SimpleXML, allow parser options to be passed to func- tions and methods that are loading XML documents (see Table B-2).

Table B-2. libxml Constants for Loading Documents Name Description LIBXML_NOENT Substitutes entities found within the document with their replacement content. LIBXML_DTDLOAD Loads any external subsets but does not perform validation. This flag also ensures that IDs set in a DTD are created within the document. LIBXML_DTDATTR Creates attributes within the document for any attributes defaulted through a DTD. LIBXML_DTDVALID Loads subsets and validates a document while parsing.

Continued 845

R. Richards, Pro PHP XML and Web Services, DOI 10.1007/978-1-4302-0139-7, © 2006 by Robert Richards 846 APPENDIX B ■ EXTENSION APIS

Table B-2. Continued Name Description LIBXML_NOERROR Suppresses errors from libxml2 that may occur while parsing. LIBXML_NOWARNING Suppresses warnings from libxml2 that may occur while parsing. LIBXML_NOBLANKS Removes all insignificant whitespace within the document. LIBXML_XINCLUDE Performs all XIncludes found within the document. LIBXML_NSCLEAN Removes redundant namespace declarations found while parsing the document. LIBXML_NOCDATA Merges CDATA nodes into text nodes. A document using CDATA sections will be created with no CDATA nodes, as these will now be converted into plain- text nodes. This flag is useful when loading a document to be used for an XSL transformation. LIBXML_NONET Disables network access when loading documents. You can use this flag to increase security from untrusted documents so resources cannot be fetched from the network. LIBXML_COMPACT Enables some memory optimizations that may help speed up an application using XML. This constant is available only when using libxml2 2.6.21 or higher.

Several constants are also defined that can be used in the context of serializing an XML document (see Table B-3). These are available only when using libxml2 2.6.21 and higher.

Table B-3. libxml Constants for Saving Documents Name Description LIBXML_NOXMLDECL Does not produce an XML declaration when saving the document LIBXML_NOEMPTYTAG Does not output empty tags; rather, always outputs an opening and closing element tag with no content between

Table B-4 lists libxml’s functions.

Table B-4. libxml Functions Function Description libxml_clear_errors(void) Clears libxml error buffer. libxml_get_errors(void) Retrieves an array of errors. libxml_get_last_error(void) Retrieves the last error from libxml. libxml_set_streams_context Sets the stream’s context for the next libxml document load or (resource streams_context) write. libxml_use_internal_errors Disables libxml errors and allows the user to fetch error infor- ([bool use_errors]) mation as needed. This returns a Boolean of the previous state.

The LibXMLError class was introduced in PHP 5.1. Objects of this type are returned from the libxml error-handling functions. A few constants are defined explicitly for use with this object (see Table B-5). Table B-6 lists the LibXMLError class properties. APPENDIX B ■ EXTENSION APIS 847

Table B-5. libxml Error-Level Constants Name Description LIBXML_ERR_NONE No error has been detected. LIBXML_ERR_WARNING This is a simple warning that the XML document may have problems. LIBXML_ERR_ERROR This is a recoverable error. The XML document contains errors, but the parser was able to continue processing. LIBXML_ERR_FATAL This means a fatal error was detected, and the parser is unable to continue processing the document.

Table B-6. LibXMLError Class Properties Property Type Description level integer Indicates the severity of the error using one of the error-level constants as its value code integer Indicates the error code from libxml2 column integer Indicates the column number, if available, from within the document where the error occurred line integer Indicates the line number, if available, from within the document where the error occurred message string Indicates the textual representation of the error file string Indicates the filename of the XML document containing the error The xml extension, covered in Chapter 8, provides a SAX parser to process XML based on events using handlers. Because this extension maintains compatibility and also can be built using expat rather than libxml2, it defines its own set of parser option constants. Table B-7 lists the xml parser’s options constants, Table B-8 lists the xml parser’s error code constants, and Table B-9 lists the xml parser’s XML functions.

Table B-7. XML Parser Options Constants Option Description XML_OPTION_TARGET_ENCODING Sets the encoding to use when the parser passes the XML informa- tion to the function handlers. The available encodings are US-ASCII, ISO-8859-1, and UTF-8. The default is either the course encoding set when the parser was created or UTF-8 when not specified. XML_OPTION_SKIP_WHITE Skips values that are entirely ignorable whitespaces. These values will not be passed to your function handlers. The default value is 0, meaning to pass whitespaces to the functions. XML_OPTION_SKIP_TAGSTART Skips a certain number of characters from the beginning of a start tag. The default value is 0 to not skip any characters. XML_OPTION_CASE_FOLDING Determines whether element tag names are passed all uppercase or left as is. The default value is 1 to uppercase all tag names. The default setting tends to be a bit controversial. XML is case-sensitive, and the default setting is to case fold characters. For example, an element named FOO is not the same as an element named Foo. 848 APPENDIX B ■ EXTENSION APIS

Table B-8. XML Error Code Constants Name XML_ERROR_NONE XML_ERROR_NO_MEMORY XML_ERROR_SYNTAX XML_ERROR_NO_ELEMENTS XML_ERROR_INVALID_TOKEN XML_ERROR_UNCLOSED_TOKEN XML_ERROR_PARTIAL_CHAR XML_ERROR_TAG_MISMATCH XML_ERROR_DUPLICATE_ATTRIBUTE XML_ERROR_JUNK_AFTER_DOC_ELEMENT XML_ERROR_PARAM_ENTITY_REF XML_ERROR_UNDEFINED_ENTITY XML_ERROR_RECURSIVE_ENTITY_REF XML_ERROR_ASYNC_ENTITY XML_ERROR_BAD_CHAR_REF XML_ERROR_BINARY_ENTITY_REF XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF XML_ERROR_MISPLACED_XML_PI XML_ERROR_UNKNOWN_ENCODING XML_ERROR_INCORRECT_ENCODING XML_ERROR_UNCLOSED_CDATA_SECTION XML_ERROR_EXTERNAL_ENTITY_HANDLING

Table B-9. XML Functions Function Description xml_parser_create([string encoding]) Creates and returns an XML parser. You can specify an optional encoding for output. xml_parser_create_ns([string encoding Creates and returns an XML parser. You can specify an [, string sep]]) optional encoding for output, and you can use an optional separator to separate the namespace with the local name. If not specified, a colon is used as the default separator. xml_set_object(resource parser, object Associates a parser with an object so callback functions will obj) use the object’s methods as handlers. This returns a Boolean indicating success or failure. xml_set_element_handler(resource parser, Sets start and end element handlers for the parser. This string shdl, string ehdl) returns a Boolean indicating success or failure. xml_set_character_data_handler(resource Sets a character data handler for the parser. This returns parser, string hdl) a Boolean indicating success or failure. APPENDIX B ■ EXTENSION APIS 849

Function Description xml_set_processing_instruction_handler Sets a PI handler for the parser. This returns a Boolean (resource parser, string hdl) indicating success or failure. xml_set_default_handler(resource parser, Sets the default handler for a parser. This functionality is string hdl) now working as of PHP 5.1. This returns a Boolean indicating success or failure. xml_set_unparsed_entity_decl_handler Sets unparsed entity declaration handler for the parser. This (resource parser, string hdl) returns a Boolean indicating success or failure. xml_set_notation_decl_handler(resource Sets the notation declaration handler for the parser. This parser, string hdl) returns a Boolean indicating success or failure. xml_set_external_entity_ref_handler Sets the external entity reference handler for the parser. This (resource parser, string hdl) returns a Boolean indicating success or failure. xml_set_start_namespace_decl_handler Sets the start namespace declaration handler for the parser. (resource parser, string hdl) This returns a Boolean indicating success or failure. xml_set_end_namespace_decl_handler Sets the end namespace declaration handler for the parser. (resource parser, string hdl) This returns a Boolean indicating success or failure. xml_parse(resource parser, string data Parses the XML sent in the data parameter. Parsing can be [, integer isFinal]) performed in chunks, and the isFinal parameter identifies whether the chunk being passed is the end of the XML document. xml_parse_into_struct(resource parser, Parses the XML into an array, values, and optionally an string data, array &values[, array array, index, containing pointers to values in the values &index]) array. xml_get_error_code(resource parser) Returns the XML parser error code. This code is a constant defined by the XML extension. xml_error_string(integer code) Returns the error string for the code. xml_get_current_line_number(resource Returns the line number the parser is currently processing. parser) xml_get_current_column_number(resource Returns the column number the parser is currently parser) processing. xml_get_current_byte_index(resource Returns the byte index the parser is currently processing. parser) xml_parser_free(resource parser) Frees the reference to the XML parser. xml_parser_set_option(resource parser, Sets the value for one of the XML parser options. This integer option, mixed value) returns a Boolean indicating success or failure. xml_parser_get_option(resource parser, Retrieves current value for an option. integer option) utf8_encode(string data) Encodes an ISO-8859-1 string to UTF-8. utf8_decode(string data) Converts a UTF-8 encoded string to ISO-8859-1.

XMLReader XMLReader, covered in Chapter 9, is a stream-based, lightweight, and simple-to-use parser. This extension is written specifically for PHP 5 and newer. It originated as a PECL extension but was not added to the main distribution until PHP 5.1. For PHP 5.1, all constants have been 850 APPENDIX B ■ EXTENSION APIS

moved to the XMLReader class rather than to global constants. Table B-10 lists the XMLReader node type constants, Table B-11 lists the options class constants, and Table B-12 lists the XMLReader properties, which are read-only.

Table B-10. XMLReader Node Type Constants Name Description NONE No current node ELEMENT Element node ATTRIBUTE Attribute node TEXT Text node CDATA CDATA node ENTITY_REF Entity reference node ENTITY Entity node PI PI node COMMENT Comment node DOC Document node DOC_TYPE Doctype node DOC_FRAGMENT Document fragment node NOTATION Notation node WHITESPACE Whitespace SIGNIFICANT_WHITESPACE Significant whitespace END_ELEMENT End element END_ENTITY End entity XML_DECLARATION XML declaration

Table B-11. XMLReader Parser Options Class Constants Name Description LOADDTD Loads DTD while parsing DEFAULTATTRS Indicates the default attributes defined in the DTD while parsing VALIDATE Validates the document while parsing SUBST_ENTITIES Substitutes entities while parsing APPENDIX B ■ EXTENSION APIS 851

Table B-12. XMLReader Properties (Read-Only) Property Type Description attributeCount integer Returns the number of attributes on the current element baseURI string Returns the base URI for the current node depth integer Returns the depth of the node within the tree using a zero-based starting point hasAttributes Boolean Indicates whether the element has any attributes hasValue Boolean Indicates whether the node has a child text node isDefault Boolean Indicates whether the attribute is defaulted from the DTD isEmptyElement Boolean Indicates whether the element is an empty element tag localName string Returns the local name of the node name string Returns the full qualified name of the node namespaceURI string Returns the namespace URI for the node nodeType integer Returns an XMLReader node type constant for the current node prefix string Returns the prefix of the current node value string Returns the text value of the node xmlLang string Returns the xml:lang scope for which the node resides

The majority of methods from the XMLReader class return a Boolean that indicates the success or failure of the operation. Unless otherwise indicated in the method description, you should assume a Boolean as the return type. Table B-13 lists the XMLReader class methods.

Table B-13. XMLReader Class Methods Method Description close() Closes the XMLReader parser and returns a Boolean indicating success or failure. getAttribute(string name) Returns the value of the attribute specified by name. getAttributeNo(integer index) Returns the value of the attribute specified by index. getAttributeNs(string name, Returns the value of the attribute specified by name and string namespaceURI) namespace. getParserProperty(integer Returns a Boolean for the value of the specified property. property) The property is identified by one of the XMLReader parser option class constants. isValid Boolean isValid() When in validating mode, returns Boolean indicating whether parsed document is valid. lookupNamespace(string prefix) Returns the namespace URI in scope for the given prefix. moveToAttribute(string name) Positions the reader on the attribute specified by name. moveToAttributeNo(integer index) Positions the reader on the attribute specified by index. moveToAttributeNs(string name, Positions the reader on the attribute identified by the name string namespaceURI) and namespace.

Continued 852 APPENDIX B ■ EXTENSION APIS

Table B-13. Continued Method Description moveToElement() When positioned on an attribute, this method positions the reader back on the containing element. moveToFirstAttribute() Positions the reader on the first attribute. moveToNextAttribute() Positions the reader on the next attribute. open(string URI [, string Sets the URI to be opened by the reader. The optional encoding [, integer options]]) parameters are currently available only in CVS for the upcoming PHP 6. You can specify the encoding of the document within the file and parser options. read() Positions the reader to the next node in the stream. next([string localname]) Moves the reader to the next node in the stream, skipping over any subtrees. Optionally, you can specify a local name, causing the reader to continually call the next method until it either has found a node with the specified name or has reached the end of the stream. setParserProperty(integer Sets the value for a specified property, which is one of the property, Boolean value) parser options. setRelaxNGSchemaSource(string Sets the URI of a RELAX NG schema to be used for validation. filename) setRelaxNGSchemaSource(string Provides a string containing a RELAX NG schema to be used source) for validation. XML(string source [, string Sets data, contained in the string parameter, to be processed encoding [, integer options]]) by the reader. The optional parameters are currently avail- able only in CVS for the upcoming PHP 6. You can specify the encoding of the document within the file and parser options. expand() Creates a copy of the node the reader is currently positioned on and returns it as the appropriate DOM class. This function is available in PHP 5.1 and newer. readInnerXml() Returns a string containing the contents of the current node, including child nodes and markup. This method is currently available only in CVS for the upcoming PHP 6. libxml2 ver- sion 2.6.20 or newer is also required for this functionality. readOuterXml() Returns a string containing current node, including its con- tents, child nodes, and markup. This method is currently available only in CVS for the upcoming PHP 6. libxml2 ver- sion 2.6.20 or newer is also required for this functionality. readString() Reads the contents of an element or a text node as a string. This method is currently available only in CVS for the upcoming PHP 6. libxml2 version 2.6.20 or newer is also required for this functionality.

SimpleXML The SimpleXML extension, covered in Chapter 7, provides a tree-based parser that allows an XML document to be manipulated as an object. Other than a few functions used to load XML data and create a SimpleXMLElement object, you perform all functionality using the APPENDIX B ■ EXTENSION APIS 853

SimpleXMLElement class. Table B-14 lists the SimpleXML functions, and Table B-15 lists the SimpleXMLElement methods.

Table B-14. SimpleXML Functions Function Description simplexml_import_dom(DOMNode node Performs a zero-copy import from a DOMNode. This function [, string class_name]) either returns a SimpleXMLElement object or returns an object from the class specified by the class_name parame- ter. When this parameter is used, the class must inherit from the SimpleXMLElement class. simplexml_load_file(string uri [, Loads the data from the location specified by the uri string class_name [, integer parameter. The class_name parameter allows the returned options]]) object to be instantiated as the specified class rather than a SimpleXMLElement, as long as the class inherits from SimpleXMLElement. The options parameter, added in PHP 5.1, allows the use of LIBXML constants appropriate when loading a document. simplexml_load_string(string data Loads the data contained in the data parameter. The [, string class_name [, integer class_name parameter allows the returned object to options]]) be instantiated as the specified class rather than a SimpleXMLElement, as long as the class inherits from SimpleXMLElement. The options parameter, added in PHP 5.1, allows the use of LIBXML constants appropriate when loading a document.

Table B-15. SimpleXMLElement Methods Name Description __construct(string data) Constructor for SimpleXMLElement. The data parameter is a string containing an XML document and is used to create the XML tree within the returned object. asXML([string uri]) Returns a well-formed XML string based on the SimpleXMLElement. attributes([string ns]) Returns a SimpleXMLElement for the attributes of an ele- ment. The ns parameter specifies a namespace for the attributes to be retrieved. children([string ns]) Returns a SimpleXMLElement for the children of an element. The ns parameter specifies a namespace for the children to be retrieved. xpath(string path) Runs XPath query on XML data returning the results in an array. registerXPathNamespace(string Registers a namespace and associated prefix that can be prefix, string namespace) used when performing XPath queries. This method was added in PHP 5.1.

Continued 854 APPENDIX B ■ EXTENSION APIS

Table B-15. Continued Name Description getDocNamespaces([bool recursive]) Returns an array containing all namespace declarations defined on the document element. When recursive is passed as TRUE, all namespace declarations in the entire document are returned. The array is an associative array using the namespace prefix as the key. Any redefined pre- fixes further in the tree when using this method recursively are not returned in the array, because their first definition takes precedence. Default namespace declarations do not have a prefix, so an empty string is used as the key in the array. This method was added in PHP 5.1.2. getNamespaces([bool recursive]) Returns an array containing all namespaces in use for the current element or attribute. When the recursive parame- ter is set to TRUE, all namespaces for child nodes are returned as well. The array is an associative array using the namespace prefix as the key. Any redefined prefixes further in the tree when using this method recursively are not returned in the array, because their first definition takes precedence. Default namespaces do not have a prefix, so an empty string is used as the key in the array. This method was added in PHP 5.1.2.

DOM The DOM extension, covered in Chapter 6, is a tree-based parser that offers the most flexibility and functionality to manipulate an XML document. As you can see from its API, it is also the most complex extension to use. Table B-16 lists the DOM node type constants, Table B-17 lists the DOM exception code constants, and Table B-18 lists the DOM functions.

Table B-16. DOM Node Type Constants Name Description XML_ELEMENT_NODE The node is a DOMElement. XML_ATTRIBUTE_NODE The node is a DOMAttr. XML_TEXT_NODE The node is a DOMText. XML_CDATA_SECTION_NODE The node is a DOMCharacterData. XML_ENTITY_REF_NODE The node is a DOMEntityReference. XML_ENTITY_NODE The node is a DOMEntity. XML_PI_NODE The node is a DOMProcessingInstruction. XML_COMMENT_NODE The node is a DOMComment. XML_DOCUMENT_NODE The node is a DOMDocument. XML_DOCUMENT_TYPE_NODE The node is a DOMDocumentType. XML_DOCUMENT_FRAG_NODE The node is a DOMDocumentFragment. XML_NOTATION_NODE The node is a DOMNotation. XML_HTML_DOCUMENT_NODE The node is a DOMDocument containing an HTML document. APPENDIX B ■ EXTENSION APIS 855

Table B-17. DOM Exception Code Constants Name Description DOM_INDEX_SIZE_ERR Indicates whether the index or size is negative or greater than the allowed value. DOMSTRING_SIZE_ERR Indicates whether the specified range of text does not fit into a DOMString. DOM_HIERARCHY_REQUEST_ERR Indicates whether any node is inserted where it doesn’t belong. DOM_WRONG_DOCUMENT_ERR Indicates whether a node is used in a different document than the one that created it. DOM_INVALID_CHARACTER_ERR Indicates whether an invalid or illegal character is specified, such as in a name. DOM_NO_DATA_ALLOWED_ERR Indicates whether data is specified for a node that does not support data. DOM_NO_MODIFICATION_ALLOWED_ERR Indicates whether an attempt is made to modify an object where modifications are not allowed. DOM_NOT_FOUND_ERR Indicates whether an attempt is made to reference a node in a context where it does not exist. DOM_NOT_SUPPORTED_ERR Indicates whether the implementation does not support the requested type of object or operation. DOM_INUSE_ATTRIBUTE_ERR Indicates whether an attempt is made to add an attribute that is already in use elsewhere. DOM_INVALID_STATE_ERR Indicates whether an attempt is made to use an object that is not, or is no longer, usable. DOM_SYNTAX_ERR Indicates whether an invalid or illegal string is specified. DOM_INVALID_MODIFICATION_ERR Indicates whether an attempt is made to modify the type of the underlying object. DOM_NAMESPACE_ERR Indicates whether an attempt is made to create or change an object in a way that is incorrect with regard to namespaces. DOM_INVALID_ACCESS_ERR Indicates whether a parameter or an operation is not supported by the underlying object. DOM_VALIDATION_ERR Indicates whether a call to a method such as insertBefore or removeChild would make the node invalid with respect to “partial validity.” This exception would be raised, and the operation would not be done.

Table B-18. DOM Functions Function Description dom_import_simplexml(SimpleXMLElement node) Imports a SimpleXMLElement and returns the corresponding DOMNode. This function per- forms a zero-copy import. 856 APPENDIX B ■ EXTENSION APIS

DOMException The DOMException class inherits from the built-in Exception class. When an exception error occurs, according to the DOM specifications, DOM throws a DOMException, unless error han- dling has been changed using the DOMDocument strictErrorChecking property. This allows a developer to explicitly catch and handle a DOMException. The value of the code property corre- sponds to one of the DOMException code constants.

DOMImplementation Table B-19 lists the DOMImplementation methods.

Table B-19. DOMImplementation Methods Method Description createDocument([string namespaceURI[, Creates a new DOMDocument object. This method is string qualifiedName[, DOMDocumentType typically used to create a document containing doctype]]]) a doctype. createDocumentType(string qualifiedName, Creates an empty DOMDocumentType object that string publicId, string systemId) can be used with the createDocument() method. hasFeature(string feature, string version) Tests whether the DOM implementation imple- ments a specific feature for a specified version.

DOMXPath Table B-20 lists the DOMXPath methods.

Table B-20. DOMXPath Methods Method Description __construct(DOMDocument doc) Constructs a new DOMXPath object for the given DOMDocument. registerNamespace(string prefix, string Registers a prefix and namespace that can be used uri) in the XPath expressions. query(string expr [,DOMNode context]) Evaluates the given XPath expression and returns a DOMNodeList containing the resulting nodes. A DOMNode can be passed to set the initial context. evaluate(string expr [,DOMNode context]) Evaluates the given XPath expression and returns a typed result if possible. A DOMNode can be passed to set the initial context. This method was added in PHP 5.1.

DOMNodeList The DOMNodeList class has a single read-only property called length. It returns the number of nodes contained within the list. Nodes are accessed using the item(integer index) method. The index parameter specifies the zero-based index of the node to retrieve from the list. APPENDIX B ■ EXTENSION APIS 857

DOMNamedNodeMap The DOMNamedNodeMap class has a single read-only property called length. It returns the number of nodes contained within the map. This class defines three methods to retrieve nodes (see Table B-21).

Table B-21. DOMNamedNodeMap Methods Method Description getNamedItem(string name) Retrieves a node specified by name. getNamedItemNS(string namespaceURI, Retrieves a node specified by local name and string localName) namespace URI. item(integer index) The index parameter specifies the zero-based index of the node to retrieve from the list.

DOMNode The DOMNode class is the base class for the majority of the rest of the DOM classes. Table B-22 lists its properties, and Table B-23 lists its methods.

Table B-22. DOMNode Properties Name Type Read-Only? Description nodeName string Yes Returns the more accurate name for the current node type. nodeValue string No The value of this node, depending on its type. nodeType integer Yes Gets the type of the node. This is one of the predefined XML_xxx_NODE constants. parentNode DOMNode Yes The parent of this node. childNodes DOMNodeList Yes A DOMNodeList that contains all children of this node. If there are no children, this is an empty DOMNodeList. firstChild DOMNode Yes The first child of this node. If there is no such node, this returns NULL. lastChild DOMNode Yes The last child of this node. If there is no such node, this returns NULL. previousSibling DOMNode Yes The node immediately preceding this node. If there is no such node, this returns NULL. nextSibling DOMNode Yes The node immediately following this node. If there is no such node, this returns NULL. attributes DOMNamedNodeMap Yes A DOMNamedNodeMap containing the attributes of this node (if it is a DOMElement) or NULL otherwise. ownerDocument DOMDocument Yes The DOMDocument object associated with this node.

Continued 858 APPENDIX B ■ EXTENSION APIS

Table B-22. Continued Name Type Read-Only? Description namespaceURI string Yes The namespace URI of this node or NULL if it is unspecified. prefix string No The namespace prefix of this node or NULL if it is unspecified. localName string Yes Returns the local part of the qualified name of this node. baseURI string Yes The absolute base URI of this node or NULL if the implementation wasn’t able to obtain an absolute URI. textContent string No This attribute returns the text content of this node and its descendants.

Table B-23. DOMNode Methods Method Description appendChild(DomNode newChild) Adds the newChild node to the end of the children. cloneNode(Boolean deep) Clones a node. If deep is specified, then all child nodes are also cloned. hasAttributes() Returns a Boolean indicating whether the node has attributes. hasChildNodes() Returns a Boolean indicating whether the node has children. isDefaultNamespace(string Returns a Boolean indicating whether the supplied namespaceURI) namespaceURI is the default namespace in scope for the node. insertBefore(DomNode newChild, Adds a new child node before a reference node. DomNode refChild) isSameNode(DomNode other) Indicates whether the current node is the same node being passed to method. isSupported(string feature, string Checks whether the feature is supported for specified version) version. lookupNamespaceURI(string prefix) Returns the namespace URI currently associated with the supplied prefix. lookupPrefix(string namespaceURI) Gets the namespace prefix of the node based on the namespace URI. normalize() Normalizes the node. removeChild(DomNode oldChild) Removes the child node from list of children. replaceChild(DomNode newChild, Replaces a child node with a different node. This method DomNode oldChild) returns the node that was replaced. APPENDIX B ■ EXTENSION APIS 859

DOMDocumentFragment DOMDocumentFragment extends DOMNode (see Table B-24).

Table B-24. DOMDocumentFragment Methods Method Description __construct() Constructs a new DOMDocumentFragment element that is not associated with a document. appendXML(string data) Builds an XML tree based on the input data within a DOMDocument➥ Fragment. This function was added in PHP 5.1.

DOMDocument DOMDocument extends DOMNode. Table B-25 lists the DOMDocument properties, and Table B-26 lists the DOMDocument methods.

Table B-25. DOMDocument Properties Name Type Read-Only? Description actualEncoding string Yes Indicates the encoding of the document. doctype DOMDocumentType Yes Indicates the document type declaration asso- ciated with this document. documentElement DOMElement Yes This is a convenience attribute that allows direct access to the child node that is the doc- ument element of the document. documentURI string No Indicates the location of the document or NULL if undefined. encoding string No Indicates the current encoding of the document. formatOutput bool No During , this property specifies whether line feeds and indentation should be added. The default value is FALSE. implementation DOMImplementation Yes Indicates that the DOMImplementation object handles this document. preserveWhiteSpace bool No Does not remove redundant whitespace. The default is TRUE. recover bool No Indicates the parser recover on a fatal error while loading the document. The default is FALSE. resolveExternals bool No Loads external entities from a doctype decla- ration. This is useful for including character entities in your XML document. standalone bool No Indicates the value of the standalone attribute from the XML declaration. strictErrorChecking bool No Throws DOMException on errors. The default is TRUE.

Continued 860 APPENDIX B ■ EXTENSION APIS

Table B-25. Continued Name Type Read-Only? Description substituteEntities bool No Determines whether the parser should substitute entities with their content when loading a document. validateOnParse bool No Loads and validates against the DTD. The default is FALSE. version string No Indicates the XML version being used in the document. xmlEncoding string Yes Specifies, as part of the XML declaration, the encoding of this document. This is NULL when unspecified or when it is not known, such as when the document was created in memory. xmlStandalone bool No Specifies, as part of the XML declaration, whether this document is stand-alone. This is FALSE when unspecified. xmlVersion string No Specifies, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the XML feature, the value is 1.0.

Table B-26. DOMDocument Methods Method Description __construct([string version[, string Creates a new DOMDocument object. encoding]]) createAttribute(string name) Creates a new attribute associated with the DOMDocument. createAttributeNS(string namespaceURI, Creates a new attribute node with an associated string qualifiedName) namespace associated with the DOMDocument. createCDATASection(string data) Creates a new CDATA node associated with the DOMDocument. createComment(string data) Creates a new comment node associated with the DOMDocument. createDocumentFragment() Creates a new document fragment associated with the DOMDocument. createElement(string tagName [, string Creates a new element node associated with the value]) DOMDocument. createElementNS(string namespaceURI, Creates a new element node with an associated string qualifiedName [,string value]) namespace associated with the DOMDocument. createEntityReference(string name) Creates a new entity reference node associated with the DOMDocument. createProcessingInstruction(string Creates a new PI node associated with the target[, string data]) DOMDocument. createTextNode(string data) Creates a new text node associated with the DOMDocument. getElementById(string elementId) Searches for an element with a certain ID. APPENDIX B ■ EXTENSION APIS 861

Method Description getElementsByTagName(string tagname) Searches for all elements with the given tag name. getElementsByTagNameNS(string Searches for all elements with given tag name in namespaceURI, string localName) specified namespace. importNode(DOMNode importedNode, Imports a node into current document. Boolean deep) load(string URI [, integer options]) Loads XML from a file. loadHTML(string source) Loads HTML from a string. loadHTMLFile(string URI) Loads HTML from a file. loadXML(string data [, integer Loads XML from a string. options]) normalizeDocument() Normalizes the document. relaxNGValidate(string filename) Performs RELAX NG validation on the document loading the schema from a URI. relaxNGValidateSource(string data) Performs RELAX NG validation on the document loading the schema from a string. save(string URI[, integer options]) Dumps the internal XML tree back into a file. saveHTML(string source) Dumps the internal document into a string using HTML formatting. saveHTMLFile(string URI) Dumps the internal document into a file using HTML formatting. saveXML([node n [, integer options]]) Dumps the internal XML tree back into a string. schemaValidate(string filename) Validates a document based on a schema loaded from a URI. schemaValidateSource(string data) Validates a document based on a schema. validate() Validates the document based on its DTD. xinclude([integer options]) Substitutes XIncludes in a DOMDocument object. registerNodeClass(string baseclass, Registers classes that will be used to create DOM string extendedclass) objects rather than the internal ones. This method is in CVS for the upcoming PHP 6.

DOMAttr DOMAttr extends DOMNode. Table B-27 lists the DOMAttr properties, and Table B-28 lists the DOMAttr methods.

Table B-27. DOMAttr Properties Name Type Read-Only? Description name string Yes The name of the attribute ownerElement DOMElement Yes The element that contains the attribute value string No The value of the attribute 862 APPENDIX B ■ EXTENSION APIS

Table B-28. DOMAttr Methods Method Description __construct(string name, [string value]) Creates a DOMAttr with a specified name and optional value isId() Returns a Boolean indicating whether the attribute is an ID

DOMElement DOMElement extends DOMNode. Table B-29 lists the DOMElement methods, and Table B-30 lists the DOMElement methods.

Table B-29. DOMElement Properties Name Type Read-Only? Description tagName string Yes The element name

Table B-30. DOMElement Methods Method Description __construct(string name, [string value Creates a DOMElement object with a specified name [, string uri]]) and optionally a value and namespace URI. getAttribute(string name) Returns the value of the attribute based on the name. getAttributeNode(string name) Returns the attribute node with the specified name. getAttributeNodeNS(string namespaceURI, Returns the attribute node with given namespace string localName) and name. getAttributeNS(string namespaceURI, Returns the value of the attribute based on string localName) namespace URI and name. getElementsByTagName(string name) Gets elements by tag name. getElementsByTagNameNS(string Gets elements by namespaceURI and localName. namespaceURI, string localName) hasAttribute(string name) Indicates whether the specified attribute exists. hasAttributeNS(string namespaceURI, Indicates whether the specified attribute exists string localName) within a namespace. removeAttribute(string name) Removes the attribute by name. removeAttributeNode(DOMAttr oldAttr) Removes the attribute from the element. removeAttributeNS(string namespaceURI, Removes the attribute by name and namespace. string localName) setAttribute(string name, string value) Adds a new attribute with the specified name and value. setAttributeNode(DOMAttr newAttr) Adds a new attribute node to the element. setAttributeNodeNS(DOMAttr newAttr) Adds a new attribute node to the element. APPENDIX B ■ EXTENSION APIS 863

Method Description setAttributeNS(string namespaceURI, Adds a new attribute in the specified namespace string qualifiedName, string value) with fully qualified name and value. setIdAttribute(string name, Boolean isId) Sets IDness of an attribute by name. This method is implemented only in CVS for upcoming PHP 6. setIdAttributeNS(string namespaceURI, Sets IDness of an attribute by name and namespace. string localName, Boolean isId) This method is implemented only in CVS for upcoming PHP 6. setIdAttributeNode(attr idAttr, Boolean Set IDness of an attribute node. This method is isId) implemented only in CVS for upcoming PHP 6.

DOMCharacterData DOMCharacterData extends DOMNode. Table B-31 lists DOMCharacterData properties, and Table B-32 lists DOMCharacterData methods.

Table B-31. DOMCharacterData Properties Name Type Read-Only? Description data string No The contents of the node length integer Yes The length of the contents

Table B-32. DOMCharacterData Methods Method Description appendData(string arg) Appends a string to the end of the character data of the node deleteData(integer offset, integer count) Removes a range of characters from the node starting at the offset insertData(integer offset, string arg) Inserts a string at the specified 16-bit unit offset replaceData(integer offset, integer count, Replaces a substring within the DOMCharacterData string arg) node substringData(integer offset, integer count) Extracts a range of data from the node

DOMComment DOMComment extends DOMCharacterData. Table B-33 lists the DOMComment method.

Table B-33. DOMComment Methods Method Description __construct([string value]) Creates a DOMComment object with the specified value 864 APPENDIX B ■ EXTENSION APIS

DOMText DOMText extends DOMCharacterData. Table B-34 lists the DOMText properties, and Table B-35 lists the DOMText methods.

Table B-34. DOMText Properties Name Type Read-Only? Description wholeText string Yes Returns all text of text nodes logically adjacent to this node, concatenated in document order

Table B-35. DOMText Methods Method Description __construct([string value]) Creates a DOMText object with specified value. splitText(integer offset) Splits the text of a DOMText node at offset, creating an adjacent DOMText node. isWhitespaceInElementContent() Returns a Boolean indicating whether the node contains only whitespace. isElementContentWhitespace() This method is depreciated by isWhitespaceInElement➥ Content().

DOMCdataSection DOMCdataSection extends DOMText. Table B-36 lists the DOMCdataSection method.

Table B-36. DOMCdataSection Methods Method Description __construct([string value]) Creates a DOMCdataSection object with the specified value

DOMDocumentType DOMDocumentType extends DOMNode. Table B-37 lists the DOMDocumentType properties.

Table B-37. DOMDocumentType Properties Name Type Read-Only? Description publicId string Yes The public identifier of the external subset. systemId string Yes The system identifier of the external subset. This can be an absolute or relative URI. name string Yes The name of DTD, that is, the name imme- diately following the DOCTYPE keyword. entities DOMNamedNodeMap Yes A DOMNamedNodeMap containing the general entities, both external and internal, declared in the DTD. APPENDIX B ■ EXTENSION APIS 865

Name Type Read-Only? Description notations DOMNamedNodeMap Yes A DOMNamedNodeMap containing the notations declared in the DTD. internalSubset string Yes The internal subset as a string, or NULL if there is none. This does not contain the delimiting square brackets.

DOMNotation DOMNotation extends DOMNode. Table B-38 lists the DOMNotation properties.

Table B-38. DOMNotation Properties Name Type Read-Only? Description publicId string Yes The public identifier of the DOMNotation systemId string Yes The system identifier of the DOMNotation

DOMEntity DOMEntity extends DOMNode. Table B-39 lists the DOMEntity properties.

Table B-39. DOMEntity Properties Name Type Read-Only? Description publicId string Yes The public identifier associated with the entity if specified and NULL otherwise. systemId string Yes The system identifier associated with the entity if specified and NULL otherwise. This can be an absolute URI or relative. notationName string Yes For unparsed entities, the name of the notation for the entity. For parsed entities, this is NULL.

DOMEntityReference DOMEntityReference extends DOMNode. Table B-40 lists the DOMEntityReference method.

Table B-40. DOMEntityReference Methods Method Description __construct([string name]) Creates a DOMEntityReference object with specified name

DOMProcessingInstruction DOMProcessingInstruction extends DOMNode. Table B-41 lists the DOMProcessingInstruction properties, and Table B-42 lists the DOMProcessingInstruction method. 866 APPENDIX B ■ EXTENSION APIS

Table B-41. DOMProcessingInstruction Properties Name Type Read-Only? Description target string Yes The target name of the PI data string No The content of the PI

Table B-42. DOMProcessingInstruction Methods Method Description __construct(string name [, string value]) Creates a DOMProcessingInstruction object with the specified target name and optionally speci- fies the value

XSL The XSL extension, detailed in Chapter 10, implements the XSL standard and performs XSL transformations. The functionality of this extension is provided through the XSLTProcessor class. Table B-43 lists the XSL constants, Table B-44 lists the XSLTProcessor properties, and Table B-45 lists the XSLTProcessor methods.

Table B-43. XSL Constants Name Value Description XSL_CLONE_AUTO 0 Allows XSL to determine whether document passed to importStylesheet() needs to be cloned XSL_CLONE_NEVER -1 Never clones document passed to importStylesheet() XSL_CLONE_ALWAYS 1 Always clones document passed to importStylesheet()

Table B-44. XSLTProcessor Properties Name Default Value Description cloneDocument XSL_CLONE_AUTO This property determines how the cloning of a document is handled when passed to the importStylesheet. It may take any of the values from Table B-43.

Table B-45. XSLTProcessor Methods Name Description getParameter(string namespace, Returns the value of the parameter specified by name. The string name) namespace parameter is currently unused. hasExsltSupport() Returns a Boolean indicating whether PHP has EXSLT support. importStylesheet(DOMDocument doc) Imports a style sheet from a DOMDocument object. APPENDIX B ■ EXTENSION APIS 867

Name Description registerPHPFunctions([mixed Enables the ability to use PHP functions as XSLT functions. function]) The function parameter was added in PHP 5.1 and allows the available functions to be called to be limited to those specified in the function parameter. It can be a string to set a single function at a time or an array to set multiple func- tions at once. removeParameter(string namespace, Removes a parameter. Returns a Boolean indicating success string name) or failure. setParameter(string namespace, Sets value for a parameter. In PHP 5.0 parameters must be mixed name [, string value]) passed one at a time passing the namespace: a string con- taining the name of the parameter and a string containing the value. In PHP 5.1 it is possible to set multiple parame- ters at once by passing the namespace and an associative array containing the parameter names, where the names are the keys and their corresponding values. Returns a Boolean indicating success or failure. transformToDoc(DOMDocument doc) Transforms the input DOMDocument containing the XML data to a resulting DOMDocument. transformToURI(DOMDocument doc, Transforms the input DOMDocument containing the XML data string uri) to URI and returning the number of bytes written to the URI. transformToXML(DOMDocument doc) Transforms the input DOMDocument containing the XML data to a resulting string.

SOAP The SOAP extension, covered in Chapter 18, provides functionality allowing for the consump- tion and creation of SOAP-based Web services. Table B-46 lists the SOAP options constants, Table B-47 lists the SOAP encoding constants, and Table B-48 lists the SOAP functions.

Table B-46. SOAP Options Constants Name Name SOAP_1_1 SOAP_ACTOR_NEXT SOAP_1_2 SOAP_ACTOR_NONE SOAP_PERSISTENCE_SESSION SOAP_ACTOR_UNLIMATERECEIVER SOAP_PERSISTENCE_REQUEST SOAP_COMPRESSION_ACCEPT SOAP_FUNCTIONS_ALL SOAP_COMPRESSION_GZIP SOAP_ENCODED SOAP_COMPRESSION_DEFLATE SOAP_LITERAL SOAP_AUTHENTICATION_BASIC SOAP_RPC SOAP_AUTHENTICATION_DIGEST SOAP_DOCUMENT 868 APPENDIX B ■ EXTENSION APIS

Table B-47. SOAP Encoding Constants Name Name Name UNKNOWN_TYPE XSD_GMONTHDAY XSD_NONPOSITIVEINTEGER XSD_ANYTYPE XSD_GYEAR XSD_NORMALIZEDSTRING XSD_ANYURI XSD_GYEARMONTH XSD_NOTATION XSD_ANYXML XSD_HEXBINARY XSD_POSITIVEINTEGER XSD_BASE64BINARY XSD_ID XSD_QNAME XSD_BOOLEAN XSD_IDREF XSD_SHORT XSD_BYTE XSD_IDREFS XSD_STRING XSD_DATE XSD_INT XSD_TIME XSD_TOKEN XSD_DATETIME XSD_INTEGER XSD_UNSIGNEDBYTE XSD_DECIMAL XSD_LANGUAGE XSD_UNSIGNEDINT XSD_DOUBLE XSD_LONG XSD_UNSIGNEDLONG XSD_DURATION XSD_NAME XSD_UNSIGNEDSHORT XSD_ENTITY XSD_NCNAME SOAP_ENC_OBJECT XSD_ENTITIES XSD_NEGATIVEINTEGER SOAP_ENC_ARRAY XSD_FLOAT XSD_NMTOKEN XSD_1999_TIMEINSTANT XSD_GDAY XSD_NMTOKENS XSD_NAMESPACE XSD_GMONTH XSD_NONNEGATIVEINTEGER XSD_1999_NAMESPACE

Table B-48. SOAP Functions Function Description use_soap_error_handler([bool handler]) This function disables SOAP error handling and uses the current PHP error handler. The SOAP error handler is enabled by default when working with a SoapClient or SoapServer. is_soap_fault(zval data) Returns a Boolean indicating whether data is a SoapFault.

SoapVar The SoapVar class defines only a constructor and is used to type and encode data:

__construct(mixed data, int encoding [, string type_name [, string type_namespace [, string node_name [, string node_namespace]]]])

Table B-49 lists the SoapVar constructor parameters. APPENDIX B ■ EXTENSION APIS 869

Table B-49. SoapVar Constructor Parameters Parameter Description data The data to pass or return encoding The encoding ID, one of the SOAP encoding constants type_name The type name type_namespace The type namespace node_name The XML node name node_namespace The XML node namespace

SoapParam The SoapParam class creates a name-based parameter. This class implements only a constructor:

__construct(mixed data, string name)

Table B-50 lists the SoapParam constructor parameters.

Table B-50. SoapParam Constructor Parameters Parameter Description data The data to pass or return. Typically this is a SoapVar object. name The name of the parameter.

SoapHeader The SoapHeader class creates SOAP header entities to be added to the SOAP message within the SOAP header:

__construct(string namespace, string name [, mixed data [, bool mustUnderstand [, mixed actor]]])

Table B-51 lists the SoapHeader constructor parameters.

Table B-51. SoapHeader Constructor Parameters Parameter Description namespace The namespace of the SOAP header element. name The name of the SOAP header element. data A SOAP header’s content. It can be a PHP value or a SoapVar object. mustUnderstand Value of the mustUnderstand attribute of the SOAP header element. actor Value of the actor attribute of the SOAP header element. This is the URI of the recipient or one of the SOAP_ACTOR_... constants. 870 APPENDIX B ■ EXTENSION APIS

SoapFault The SoapFault class creates SOAP faults from a server that are returned to the calling client to be handled:

__construct(string faultcode, string faultstring [, string faultactor [, mixed detail [, string faultname [, SoapHeader headerfault]]]])

Table B-52 lists the SoapFault constructor parameters.

Table B-52. SoapFault Constructor Parameters Parameter Description faultcode The error code of the SoapFault faultstring The error message of the SoapFault faultactor A string identifying the actor that caused the error detail A PHP variable or SoapVar object to pass in the SOAP fault detail faultname Can be used to select the proper fault encoding from WSDL headerfault Can be used during SOAP header handling to report an error in the response header

SoapClient The SoapClient class creates SOAP messages and makes SOAP requests. Table B-53 lists the SoapClient methods.

Table B-53. SoapClient Methods Method Description __construct( mixed wsdl [, array options]) Constructor for SoapClient. __getLastRequest() Returns a string containing the last SOAP mes- sage request when the trace option is enabled. __getLastResponse() Returns a string containing the last SOAP mes- sage response when the trace option is enabled. __getLastRequestHeaders() Returns a string containing the last request headers when the trace option is enabled. __getLastResponseHeaders() Returns a string containing the last response headers when the trace option is enabled. __getFunctions() Returns an array of functions extracted from the WSDL. __getTypes() Returns an array of types extracted from the WSDL. __doRequest(string request, string This method is called by the SoapClient class location, string action, int version) when a request is made. Implementing this method in a subclassed SoapClient object allows access and modification to the SOAP message prior to the request being sent to a SOAP server. When implemented, it is required that the parent’s __doRequest method be called for the request to be made. APPENDIX B ■ EXTENSION APIS 871

Method Description __soapCall (string function_name [, array Calls a function by name and returns appro- arguments [, array options [, mixed priate typed data. This method depreciated input_headers [, array &output_headers]]]]) __call() in PHP 5.0.2. __setCookie(string name [, string value]) Sets a cookie that is sent with the request. This method was added in PHP 5.0.4. __setLocation([string new_location]) Sets a new URL (endpoint) for the SoapClient. This method was added in PHP 5.0.4. __setSoapHeaders(array SoapHeaders) Sets SOAP headers by passing an array of SoapHeader objects, replacing any previously set headers. This method was added in PHP 5.0.5.

SoapServer Table B-54 calls the SoapClient methods.

Table B-54. SoapClient Methods Method Description __construct( mixed wsdl [, array Constructor for SoapServer. options]) setClass(string class_name [, Sets the class and its constructor arguments that will mixed args]) handle SOAP requests. addFunction(mixed functions) Registers function handlers either one at a time, by array, or all at once using SOAP_FUNCTIONS_ALL constant. getFunctions() Returns an array of functions registered with the server. handle([string soap_request]) Handles a SOAP request. A SOAP message can be passed directly rather than retrieved automatically. setPersistence(int mode) Sets the persistence mode of SoapServer using one of the persistence constants. fault(string code, string string Issues a SOAP fault. [, string actor [, mixed details [, string name]]])

XMLWriter The XMLWriter extension, mentioned in Chapter 21, is an API to create XML-serialized XML documents using a simple interface. It was added to the default PHP distribution in PHP 5.1.2. It originally was a PECL extension developed for PHP 4.3 using procedural calls, but an object- oriented interface was added for PHP 5. The API documented here is for the object-oriented interface using the XMLWriter class. Table B-55 lists the XMLWriter class methods. 872 APPENDIX B ■ EXTENSION APIS

Table B-55. XMLWriter Class Methods Method Description openUri(string source) Initializes the writer and sets the URI to which the data will be written. openMemory() Initializes the writer using memory to provide string output. outputMemory([bool flush]) Returns the current data in the memory buffer as a string. The memory buffer can be cleared when flush is passed as TRUE. flush([bool empty]) Sends the writer buffer to the output. The return type depends upon the output method being used (memory or URI). The empty parameter, default FALSE, determines whether the writer buffer is cleared when data is sent to output. setIndent(bool indent) Turns indenting on/off. The default setting is off. setIndentString(string Sets string to use for indenting. indentString) startComment() Starts a comment. endComment() Closes an open comment. writeComment(string content) Creates a complete comment tag. StartAttribute(string name) Starts an attribute. endAttribute() Closes an open attribute. writeAttribute(string name, Creates a complete attribute with a name and content. string content) startAttributeNs(string prefix, Starts a namespaced attribute. libxml 2.6.17 and newer is string name, string uri) required for this method. startElement(string name) Starts an element. endElement() Closes an open element. startElementNs(string prefix, Starts a namespaced element tag. string name, string uri) writeElement(string name, Creates a complete element tag. string content) writeElementNs(string prefix, Creates a complete namespace element tag. string name, string uri, string content) startPi(string target) Starts a PI tag. endPi() Closes an open PI. writePi(string target, string Creates a complete PI tag. content) startCdata() Starts a CDATA section. endCdata() Closes an open CDATA section. writeCdata(string content) Creates a complete CDATA section. text(string content) Writes some text within current context. startDocument([string version[, Starts a document setting as version, encoding, and standalone. string encoding[, string standalone]]]) APPENDIX B ■ EXTENSION APIS 873

Method Description endDocument() Closes an open document. startDtd(string name[, string Starts a DTD tag. pubid[, string sysid]]) endDtd() Closes an open DTD tag. writeDtd(string name[, string Creates a complete DTD tag. pubid[, string sysid[, string subset]]]) startDtdElement(string name) Starts a DTD element. endDtdElement() Closes an open DTD element. APPENDIX C ■ ■ ■ Features and Changes in PHP 6

Technology is in a continual state of perpetual motion. It is nearly impossible to keep up with all the changes and new features. This also holds true within PHP. During the time it took to write the chapters in this book, PHP has added new functionality and has fixed or changed some behavior. This appendix addresses some of these changes and introduces some new functionality that will be released with PHP 6.

■Note Although most of the new features mentioned in this chapter are currently planned to be released in PHP 6, it is possible they may be introduced in an earlier version depending upon the PHP release schedule. xml Extension Chapter 8 pointed out the problems of using default handlers. When using the xml extension under PHP 4 and implementing a default handler, any data not handled by any other handler will use the default handler. Under PHP 5, when defined, the default handler will process only comments and entities. With the release of PHP 5.1, this has changed. Although XML declara- tions and DTDs are still not handled, other types of data, otherwise unhandled in PHP 5.0, are now processed by the default handler. Listing C-1 demonstrates how to parse a document containing various node types using only a default handler. The results shown in Listings C-2 and C-3 demonstrate the difference in output when the code is executed in PHP 5.0 and in PHP 5.1.

Listing C-1. Parsing XML Using Default Handler

875

R. Richards, Pro PHP XML and Web Services, DOI 10.1007/978-1-4302-0139-7, © 2006 by Robert Richards 876 APPENDIX C ■ FEATURES AND CHANGES IN PHP 6

$xmldata = ' some content '; $xml_parser = xml_parser_create(); xml_parser_set_option ($xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_set_default_handler($xml_parser, "defaultData"); xml_parse($xml_parser, $xmldata, true); ?>

Listing C-2. Results Under PHP 5.0

Listing C-3. Results Under PHP 5.1

some content

XMLReader Extension Once PHP 6 is released, XMLReader will provide some new functionality. Probably the most notable feature is the ability to specify the encoding of the XML and parser options from the libxml extension. For example:

boolean open(string URI [, string encoding [, int options]]) boolean XML(string source [, string encoding [, int options]])

The ability to specify an encoding might not seem all that exciting, but being able to specify parser options now means that XMLReader can perform an XInclude as it processes a document. For example, Listing C-5 shows how to process a document that contains an xinclude call to retrieve only a specific course element from the document in Listing C-4. When the first XML document contained in Listing C-5 is loaded into the XMLReader object, the LIBXML_XINCLUDE parser option is specified, resulting in the XMLReader object also pro- cessing the specified course element, shown by the results in Listing C-5. APPENDIX C ■ FEATURES AND CHANGES IN PHP 6 877

Listing C-4. External Document courses.xml

Basic Languages Introduction to Languages 1.5 2004-09-01T11:13:01 French I Introduction to French 3.0 2005-06-01T14:21:37

Listing C-5. XMLReader Using XInclude and Resulting Output

Element not found ';

$reader = new XMLReader();

/* Load the XML document, and pass the LIBXML_XINCLUDE parser option */ $reader->XML($xincdata, NULL, LIBXML_XINCLUDE); while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { print $reader->localName; /* If element is named title, move to text node and output contents */ if ($reader->localName == 'title') { $reader->read(); print ": ".$reader->value; } print "\n"; } } ?> 878 APPENDIX C ■ FEATURES AND CHANGES IN PHP 6

academic course title: Basic Languages description credits lastmodified

Three other new methods allow for text content to be accessed in a simpler manner. These new methods, shown in Table C-1, are available only when PHP is built with libxml2-2.6.20 and higher. None of the methods take any parameters, and all return a string.

Table C-1. New XMLReader Methods for PHP 6 Method Description readInnerXml() Returns a string containing the contents of the current node, which includes child nodes and markup. readOuterXml() Returns a string containing the current node and all of its contents, which includes child nodes and markup. readString() Returns a string containing the contents an element or text node. When posi- tioned on an element, the content of all text and CDATA nodes within the subtree of the element are concatenated together in the resulting string.

The example in Listing C-6 uses XMLReader to process a document containing various node types. I have not modified the results in order to demonstrate that all text nodes, includ- ing the whitespaces, are returned in the resulting string from each of the method calls.

Listing C-6. Example Calling readString(), readInnerXml(), and readOuterXml()

some content ';

$reader = new XMLReader(); $reader->XML($xmldata); while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { switch ($reader->localName) { case 'root': print "readInnerXML():\n"; print $reader->readInnerXml()."\n"; print "readString():\n"; APPENDIX C ■ FEATURES AND CHANGES IN PHP 6 879

print $reader->readString()."\n"; break; case 'e1': print "readOuterXML():\n"; print $reader->readOuterXML()."\n"; } } } ?> readInnerXML():

some content readString():

some content

more content readOuterXML(): some content

SimpleXML Extension No time has been wasted with the SimpleXML extension. As of PHP 5.1.2, two new methods have been introduced, getNamespaces() and getDocNamespaces(), and the resulting structure from calling var_dump() with a SimpleXMLElement has changed for the better. Working with namespaced documents is probably the area that causes the most problems for developers working with SimpleXML. To access an element or attribute within a name- space, and not the default namespace, you must specify the namespace URI. The issue faced is that it is up to the developer to remember all the namespaces used throughout the docu- ment. The only way to introspect the document for namespaces is to import it into DOM and use XPath to locate namespaces. That is, that was the only way until now. The getNamespaces() and getDocNamespaces() methods return an associative array of namespaces where the prefix is the key and the namespace URI is the value. The difference between the two methods is the scope of the document that is searched and the type of name- space returned in the array. The getNamespaces() method operates on the current element. The namespace URI for which the element resides in, if any, is added in the returned array. The getDocNamespaces() method uses the document element as the starting point rather than 880 APPENDIX C ■ FEATURES AND CHANGES IN PHP 6

the element from which it is called. This method not only adds the namespace of the docu- ment element but also any namespaces that have been declared on the document element.

■Note Prefixes are not used with default namespaces. If a default namespace is added to the return array by either of these functions, the key for the item is an empty string.

These methods also take an optional Boolean parameter, recursive. When passed as TRUE, both methods will also add namespaces found within the starting element’s subtree to the array as well. The use of the recursive parameter might give you pause. It is perfectly legal for prefixes to change their namespace associations within a document. Even default namespaces can be changed for different scopes. Then how do you deal with the issue of using prefixes for the array keys? When working with SimpleXML, it naturally would be more important to know about namespaces within an element that are closer to the element rather than ones that have been redefined and reside further down in the subtree. The returned array, when called recursively, returns the first namespace URIs encountered that have their prefixes redefined further within the tree. This may be a bit hard to visualize, so the example in Listing C-7 should clarify this.

Listing C-7. Retrieving Namespace URIs with SimpleXML

';

$sxe = simplexml_load_string($xmldata);

/* getDocNamespaces() call */ $arnames = $sxe->getDocNamespaces(); print "Doc Namespaces: \n"; foreach ($arnames AS $prefix=>$namespace) { print " Prefix: $prefix URI: $namespace \n"; }

/* Recursive getDocNamespaces() call */ $arnames = $sxe->getDocNamespaces(TRUE); print "\nDoc Namespaces Recursive: \n"; foreach ($arnames AS $prefix=>$namespace) { print " Prefix: $prefix URI: $namespace \n"; } APPENDIX C ■ FEATURES AND CHANGES IN PHP 6 881

/* getNamespace() call */ $a_ns = $sxe->children('urn:namespace:A'); $node_1 = $a_ns->node_1; $arnames = $node_1->getNamespaces(); print "\nElement a:node_1 Namespaces: \n"; foreach ($arnames AS $prefix=>$namespace) { print " Prefix: $prefix URI: $namespace \n"; }

/* Recursive getNamespace() call */ $arnames = $node_1->getNamespaces(TRUE); print "\nElement a:node_1 Recursive: \n"; foreach ($arnames AS $prefix=>$namespace) { print " Prefix: $prefix URI: $namespace \n"; } ?>

Doc Namespaces: Prefix: a URI: urn:namespace:A Prefix: b URI: urn:namespace:B

Doc Namespaces Recursive: Prefix: a URI: urn:namespace:A Prefix: b URI: urn:namespace:B Prefix: URI: urn:newns:C

Element a:node_1 Namespaces: Prefix: a URI: urn:namespace:A

Element a:node_1 Recursive: Prefix: a URI: urn:namespace:A

As you can see by the results, the first call to getDocNamespaces() returns the two name- spaces, urn:namespace:A and urn:namespace:B, that are declared on the document element, root. The next call to the method is performed recursively by passing TRUE as the parameter. In this case, not only the two namespaces from the previous method call are returned but also the urn:newns:C namespace is returned. The namespace urn:newns:A, from the a:node element, is not returned in this case because the prefix a has already been mapped from the declaration of the urn:namespace:A namespace on the document element. The last two getNamespaces() method calls return namespaces that are actually used and not only declared within the scope of the element from which the method is called. From the code in Listing C-7, the method is called using the a:node_1 element as the starting point. The first call to getNamespaces() simply returns the namespace urn:namespace:A, which is the namespace in which the element resides. The second call to the method is performed recursively. Because the prefix a has already been added to the array being returned, the urn:newns:A namespace is not added to the returned array. 882 APPENDIX C ■ FEATURES AND CHANGES IN PHP 6

Besides the addition of these two methods, the data returned by calling var_dump() on a SimpleXMLElement has also changed. First, attributes are now included in the output. SimpleXMLElement objects containing attributes will be output, with this function containing an additional property named @attributes. The value of this property is an array containing its attributes. Second, how objects deal with namespaces has changed. The var_dump() func- tion now also respects the namespace of the object, meaning that any child elements included in the output are within the same namespace of the object with which the function was called. Prior to this change, namespaces were not respected, and all elements within the objects sub- tree were output. Listing C-8 uses a document where one of the child course elements resides in a prefixed namespace. Each of the course elements also contains a cid attribute. You will notice the dif- ference between the output when the script is executed using PHP 5.0, shown in Listing C-9, and the output when executed using PHP 5.1.2, shown in Listing C-10. Not only do you see the attributes in Listing C-10, but only the first course element is contained in the output. The object being passed to var_dump() has not had any namespace specified, such as creating an object using the children(namespaceURI) method, so only children not within a namespace or within the default namespace will be included.

Listing C-8. Using var_dump() with SimpleXMLElement

Basic Languages French I '; $sxe = simplexml_load_string($xmldata); var_dump($sxe); ?>

Listing C-9. PHP 5.0 Results from Listing C-8

object(SimpleXMLElement)#1 (1) { ["course"]=> array(2) { [0]=> object(SimpleXMLElement)#2 (1) { ["title"]=> string(15) "Basic Languages" } APPENDIX C ■ FEATURES AND CHANGES IN PHP 6 883

[1]=> object(SimpleXMLElement)#3 (2) { ["comment"]=> object(SimpleXMLElement)#4 (0) { } ["title"]=> string(8) "French I" } } }

Listing C-10. PHP 5.1.2 Results from Listing C-8 object(SimpleXMLElement)#1 (1) { ["course"]=> object(SimpleXMLElement)#2 (2) { ["@attributes"]=> array(1) { ["cid"]=> string(2) "c1" } ["title"]=> string(15) "Basic Languages" } }

DOM Extension Not to be left out, the DOM extension contains new functionality for PHP 6. Developers who regularly use this extension will be excited to know that one of the most requested features has finally been implemented—the ability to have DOM return nodes using extended classes rather than the built-in ones. Before going into more details on this, I will mention the other new functionality that has been implemented, because it is now possible to add and remove IDs using any attribute. The DOM specification defines the setIdAttribute(), setIdAttributeNS(), and setIdAttributeNode() methods on a DOMElement object. Until now, these have not been imple- mented in the DOM extension. The methods do not create new attributes in a document. The parameters passed are used to locate a specific attribute and indicate whether it should be an ID. For example: setIdAttribute(string name, boolean isId) setIdAttributeNS(string namespaceURI, string localName, boolean isId) setIdAttributeNode(DOMAttr idAttr, boolean isId)

Prior to these methods, the only way to create the attribute ID in a document was to use a DTD to specify an attribute is of the ID type or use the xml:id attribute. This was limiting because the DTD cannot be changed after the document has been loaded, so attributes not 884 APPENDIX C ■ FEATURES AND CHANGES IN PHP 6

specified in the DTD could not be made into an ID. Also, once an attribute was made into an ID, you had no way to remove the ID other than to physically remove the entire attribute from the document. Listing C-11 demonstrates how to set and remove an ID on a document not containing a DTD and use only these new methods.

Listing C-11. Setting Attribute IDs Using DOMElement Methods

Basic Languages ';

$dom = new DOMDocument(); $dom->loadXML($xmldata); $root = $dom->documentElement; $node = $root->firstChild; $course = $node->nextSibling;

$course->setIDAttribute('cid', TRUE); print "setIDAttribute - TRUE\n "; if ($element = $dom->getElementByID('c1')) { print $element->nodeName; } else { print "ID Does not exist"; }

$attr = $course->getAttributeNode('cid'); $course->setIDAttributeNode($attr, FALSE); print "\n\nsetIDAttributeNode - FALSE\n "; if ($element = $dom->getElementByID('c1')) { print $element->nodeName; } else { print "ID Does not exist"; } ?>

setIDAttribute - TRUE course

setIDAttributeNode - FALSE ID Does not exist APPENDIX C ■ FEATURES AND CHANGES IN PHP 6 885

Finally, I will now cover probably one of the most requested features for DOM. The normal method for creating objects based on a class that extends one of the DOM classes and inserting it into the tree was to create the node using the new keyword to instantiate an object of the extended class type. This node was then inserted into the tree using any of the various DOM methods applicable for this action. This method had a few drawbacks. Probably the most important one was that you should use the createXXXX() methods from DOMDocument when creating a new node to properly create it with a document association. The other big drawback, which mostly affected developers, was that once the newly created object fell out of scope and no longer had any refer- ences, the next time the node was accessed, the object returned would be based on one of the internal DOM classes and no longer the extended class type. The good news is that you can finally do this—or at least once PHP 6 rolls around, you will be able to do this. The registerNodeClass() method has been added to the DOMDocument class. This method allows a user class that extends any of the DOM classes based on DOMNode to be reg- istered with a document and cause the extended class to be instantiated when needed rather than the internal DOM class. Every method within DOM will respect the class registration: registerNodeClass(string baseclass, string extendedclass)

This method takes two parameters and returns a Boolean indicating whether registration was successful. The first parameter, baseclass, is the name of the DOM class that the user class is replacing. The extendedclass parameter is either the name of the user class to register, which must inherit from baseclass, or NULL. When NULL is passed, any class that may have pre- viously been registered for the baseclass will unregister itself, causing the baseclass to once again be used as the class type when objects are created.

■Note Classes are registered per document and not per request. This also means that reusing a DOMDocument object for multiple XML documents will reset the registered classes to the original empty state each time a new document is loaded.

As mentioned in the previous note, classes are registered per document. This means every time a new document is created, you must register your classes. For example, each of the fol- lowing calls creates a new document:

/* Create a new empty document */ $dom = new DOMdocument();

/* Load a string creating a new document */ $dom->loadXML(...);

/* Load a URI creating a new document */ $dom->load(...);

Based on this, unless you are creating a new document from scratch, you would not regis- ter any classes until after having called one of the load methods. A benefit of this being based on a document, however, is that if you are working on two or more documents simultaneously, 886 APPENDIX C ■ FEATURES AND CHANGES IN PHP 6

each document can use a different class for a node type, rather than only a single class per node type for every document. This may sound more complex than it really is. Listing C-12 should make things much clearer.

Listing C-12. Registering Extended Classes in DOM

nodeName."\n"; print "Node Contents: ".$this->nodeValue."\n"; } }

$xmldata = ' Basic Languages ';

$dom = new DOMDocument(); /* Load the XML, and remove blanks for simplicity */ $dom->loadXML($xmldata, LIBXML_NOBLANKS);

/* Register the userElement class */ print "Register userElement class\n\n"; $dom->registerNodeClass('DOMElement', 'userElement'); $root = $dom->documentElement; $course = $root->firstChild; $title = $course->firstChild; $title->customFunction();

/* Unregister our custom class */ print "Unregister Custom Class\n\n"; $dom->registerNodeClass('DOMElement', NULL); print "Remove reference to title node using unset()\n\n"; /* Call unset() to remove reference to title node */ unset($title); ?>

Register userElement class

Node Name: title Node Contents: Basic Languages Unregister Custom Class APPENDIX C ■ FEATURES AND CHANGES IN PHP 6 887

Remove reference to title node using unset() course element is of the userElement class title element is of the DOMElement class

No longer do you need to use the new keyword. The ability to register classes with a docu- ment solves many of the issues developers have had when a subclassed object loses scope. Even when a class was unregistered, objects in scope that were created based on the extended class remain the extended class type until they also lose scope. Listing C-12 demonstrated this with the course element. This still does not provide persistence; when an object goes out of scope, it is re-created when the node is accessed again. Therefore, property values will be reset, but all the functions of the class are available. Index

■Symbols all element, 78, 86 { } (curly braces), 349–350 allow_url_fopen option, 175–176 / (forward slash), 21 Amazon E-Commerce Service (ECS), 13, 660, 781–785 ( ) (parentheses), 49, 51 Amazon Historical Pricing Service, 660 [ ] (square brackets), 26, 48 Amazon Simple Queue Service, 660 < (angle bracket) Amazon Web services, 660–661 attribute values, 25 error format, 661–663 comments, 27–28 item searches, 663–666 entity references, 17 registering, 661 PCDATA content, 53 remote shopping cart, 666–672, 784–785 processing instructions, 28 Services_Amazon PEAR package, 781–785 start and end tags, 21 ancestor axis, 128 > (angle bracket) ancestor-or-self axis, 128 comments, 27–28 and operator, 132 entity references, 17 andAllKeys option, 767 processing instructions, 28 annotation elements, 88 start and end tags, 21 ANSI (American National Standards Institute), 14 = (equal sign), 132 any element, 84 >= (greater than or equal to sign), 132 ANY value, 50, 84 > (greater than sign), 132 anyAttribute element, 84 <= (less than or equal to sign), 132 anyName pattern, 105 < (less than sign), 132 anySimpleType type, 839 + (plus sign), 49, 132 anyType type, 84, 839 ? (question mark), 28, 49 anyURI type, 840 ' (single quote), 17, 24, 25 API versioning, URIs and, 638–639 ! (exclamation point), 26, 27–28 appendChild() method, 206–207, 209–210, 858 != (not equal sign), 132 appendData() method, 863 appendXML() method, 859 ■A appid parameter, 648, 652 appinfo element, 88 about attribute application-specific instructions. See PIs channel element, RSS 1.0, 524 (processing instructions) image element, RSS 1.0, 526 applying templates, 345–347 item element, RSS 1.0, 527 array element, 572, 599–600 absolute paths, XPath, 127 array type, 569 accept attribute, 153 array type definitions, 678–679 accept-language attribute, 153 arrays accessPoint element, 759, 760 parsing data into, 288–291 acronyms, 14 serializing, 506–510 actor attribute, 700, 708 unserializing, 510–512 Actor parameter, 664 Artist parameter, 664 actor parameter, 724, 731, 869 AssociateTag parameter, 667 actualEncoding property, 859 Association of Shareware Professionals (ASP), 230 addChild() method, 500 asXML() method, 241, 853 addFunction() method, 727, 871 Asynchronous JavaScript Technology and XML add_publisherAssertions() function, 768 (Ajax), 826–830 address element, 756 Atkinson, Bob, 10 address structure, 756–757 Atom, 522. See also RSS technologies addressLine attribute, 757 Atom entry documents, 543, 549–550 adult_ok parameter, 648 Atom feed documents, 542–543, 547–549 AdWords API, 13, 744 constructs, 543–547 Ajax (Asynchronous JavaScript Technology and document structure, 543 XML), 826–830 sample document, 542 Al-Ghosein, Mohsen, 10 selecting feed technologies, 550–551 Alexa Web Information Service, 660 889

R. Richards, Pro PHP XML and Web Services, DOI 10.1007/978-1-4302-0139-7, © 2006 by Robert Richards 890 ■INDEX

using DOM (example), 551–555, 557–560 unqualified local declarations, 94–95 using XMLReader (example), 561–563 usage options, 79 Atom class, 557–560 user-defined types, 80–83 Atom entry documents, 543, 549–550 authentication. See also digital signatures Atom feed documents, 542–543, 547–549 eBay Web services, 743 atomCommonAttributes definition, 543 SOAP messages, 719 ATTLIST declarations, 36–38, 59–66 UDDI registries, 773–774 Attr interface, DOM, 187 XML signatures, 460 ATTRIBUTE constant, 318, 850 authentication option, 711 attribute declarations author element attribute IDs, 36–41, 64 entry element, Atom, 549, 558 attribute-list declarations, 59–66 feed element, Atom, 548, 558 namespaces in XML schemas, 94–97 item element, RSS 2.0, 540 RELAX NG schemas, 101–102, 113–114 Author parameter, 664 attribute default values, 60–62 authorizedName attribute, 755, 761 attribute groups, 79 AverageRating element, 653 attribute IDs, 36–41, 64 axes, XPath, 127–128, 131–132 attribute-list declarations, 59–66 attribute nodes ■B canonical XML, 455 base attribute, 42–43, 543 DOM extension, 207–208 base64 element, 599, 610–611 XPath, 124, 125–126 Base64 encoding, 27, 67 attribute pattern, 112, 113–114 base types, 73 attribute sets, XSLT, 352–353 base URIs, 42–43 attribute types, 62–66 base64Binary type, 841 attribute values, 25, 326, 450 baseURI property, 321, 851, 858 attribute XPath axis, 128 Berners-Lee, Tim, 3 attributeCount property, 321, 851 binary data in CDATA sections, 27 attributeFormDefault attribute, 95–97 binary element, 576 attributeGroup element, 79 binary large object (BLOB) fields, 8 attributes, 24 binary type, 569 case sensitivity, 17–18 binding attribute, 695–696 child elements vs., 25–26 binding definitions, WSDL, 681 creating using XSLT, 351–352 SOAP binding, 691 IDs, 36–41, 64 SOAP headers, 694 in canonical XML, 450, 451–453, 457 SOAP operation, 692–693 in DOM, 201–203 WSDL operation, 691–692, 693–694 in DTDs, 36–38, 40–41, 59–66, 64 binding element, 690–691 in RELAX NG schemas, 113–114 bindingKey attribute, 759 in SimpleXML, 255–257 bindingTemplate structure, 758–760 in XML documents, 24–26 bindingTemplates attribute, 758 in XML schemas. See attributes (XML schemas) blogInfo() method, 790, 791–792 namespaces and, 31, 32, 35–36 blogPostTags() method, 790, 792–793 naming, 24–25 body, XML documents, 20 types, 62–66 Body element, 701 usage guidelines, 25–26 BOM (byte order mark), 19, 169 values, 25 bookmarks, online, 785–786 XMLReader access, 325–327 boolean element, 571, 597 attributes key, 289 boolean() function, 138 attributes() method, 256, 259, 853 boolean type, 569, 840 attributes property, 857 Box, Don, 10 attributes (XML schemas). See also attributes; buffering documents, XMLWriter, 817–818 schemas, XML bug fixes, libxml2, and libxslt libraries, 164 attribute groups, 79 built-in types, 73 declaring, 73, 74–75, 79 built-in XSL templates, 347–348 default values, 79 businessEntity structure, 754–757, 774 global declarations, 95 businessKey attribute, 755, 758 local declarations, 95 businessService structure, 757–758 namespaces and, 76, 94–100 businessServices element, 755 qualified local declarations, 95–97 byte index, 291–292, 304 simple types, 72–73, 83–84 byte type, 842 ■INDEX 891

■C channels, RSS, 524–526, 531, 532, 536–537 Cache element, 650 character data cached pages, retrieving, 787 CDATA attribute type, 62–63 calculations, XPath expressions, 146, 160 character data event handlers, 275–279, 284, 308 _call() method, 743–744 in canonical XML, 450 callbacks, 826 in DOM parser example, 308 call_using_curl() function, 601 in XML documents, 16–17 call_using_sockets() function, 601 markup vs., 16–17 canonical XML character data encryption, 476 attribute nodes, 455 character data handlers, 301 canonical form requirements, 449–451 character encodings, 19 comment nodes, 456 character escaping, 146 element nodes, 454 character references, 15–16, 17, 62, 450 empty namespace declarations, 454 CharacterData interface, 184, 186 encrypting data, 482 characters exclusive XML canonicalization, 456–460 allowed in names, 16 namespace nodes, 454–455 case sensitivity, 17–18, 64 node ordering, 450, 451–453 character references, 15–16, 17, 62, 450 processing instruction nodes, 455–456 decimal, hexadecimal equivalents, 15–16 root node, 453 restricted characters, 17, 25 text nodes, 455 Unicode character set, 15 Find http://superindex.apress.com/ it faster at whitespace, 455 whitespace characters, 16 CanonicalizationMethod element, 464, 470, 473 child axis, XPath, 128 cards, WML, 831 child content model, 50–52 carriage return character child elements formatting XML documents, 23–24 attributes vs., 25–26 in canonical XML, 455 child content model, 50–52 in SAX parser, 277, 278 complex types, 73–76, 84–85 in user-derived types, 81–82 in RELAX NG schemas, 101–103, 105 in XML documents, 16 in SimpleXML, 244, 245, 246–250, 252 CartAdd operation, 670–671 mixing with text content, 85–86 CartClear operation, 670 nested elements, 23–24 CartId element, 669 child nodes, DOM extension, 196–197 CartItemId element, 671 childNodes property, 196–197, 857 CartModify operation, 671 children() method, 246–247, 259, 853 Cascading Style Sheets, WAP (WCSS), 835 children property, 500 case folding, SAX parser, 273 choice element, 78 case-order attribute, 362 choice pattern, 105, 106, 114 case sensitivity, 17–18, 64 chunking data, SAX parser, 286–287, 304 caseFolding option, 502 CipherData element, 479–480, 483, 485, 487 caseFoldingTo option, 502 CipherReference element, 480, 487 caseSensitiveMatch, 766 CipherValue element, 480, 483, 487 Catalog element, 652, 656 circular entity references, 55 category element class definitions, WSDL, 679–680 Atom, 546 classaddFunction() method, 727, 871 entry element, Atom, 549 classes, DOM extension feed element, Atom, 548 constructors, 220 item element, RSS 2.0, 540 extending, 219–220, 226, 228 categoryBag attribute, 758 methods, 221 categoryBag element, 755, 762 migrating from domxml extension, 228–230 CDATA constant objects, classes, and interfaces, 183, 184, cdata() method, 518 186–187, 885–887 cdata-section-elements attribute, 382, 384 properties, 220–221 CDATA sections, 173–174, 277–278, 450 registering, 885–887 CDATA type, 62–63. See also NMTOKEN, scope and object lifetime, 221–223, 226, NMTOKENS types 885–887 cdataHandler() method, 494 classes, SimpleXML extension, 257–258 CDATASection interface, 187 classmap option, 711 ceiling() function, 138 classmap parameter, 724 certificates, XML signatures, 465 ClickUrl element, 650 channel element, 524–526, 530–532, 536–537, 552, Client fault code, SOAP, 702 555, 556 892 ■INDEX

clients DOMText class, 864 REST Web service (example), 643–645 DOMXPath class, 856 SOAP. See SOAP clients SoapClient class, 710–712, 870 validating server-based data, 826–830 SoapFault class, 870 WDDX Web service (example), 587–589 SoapHeader class, 708, 869 XML-RPC, 612–617, 625, 628 SoapParam class, 869 cloneDocument property, 389, 866 SoapServer class, 724–725, 871 cloneNode() method, 858 SoapVar class, 707, 868–869 close() method, 851 constructors, DOM classes, 220 code property, 178, 847 contact structure, 756 collections contacts element, 755 iterating, 196–197, 201–202, 225, 245–246 contains() function, 137 NameNodeMap interface, 184, 186, 225 content NodeList interface, 184, 186 complex element content, 86–87 of attributes, 201–202 default element content, 76–77 of elements, 245–246 element content, 21 of node sets, 358–360, 360–362, 406–407 empty element content, 112–113 of nodes, 196–197, 225 fixed element content, 76–77 removing nodes, 225 mixed element content, 85–86, 107–108, 111–112 collisions, namespace, 31 PCDATA content, 52–54 column number, SAX, 291–292, 303–304 reusing. See XInclude column property, 178, 847 content blocks, RSS, 527–528, 532–534, 539–541 combineCategoryBags option, 767 content element, 546, 549 combining schemas content management systems (CMS), 6–7 local vs. global declarations, 93 Content module, 532–534 namespaces and, 94–100 content syndication. See syndication using import elements, 97–100 context nodes, XPath, 127, 134 using include elements, 91–93 contexts (stream contexts), 176–177 COMMENT constant, 317, 318, 850 contributor element, 548, 550 Comment interface, 187 convenience of parsers. See parser comparisons comment() method, 518 converting document encoding, 171–172 comment nodes copying canonical XML, 456 nodes, 354–355 CharacterData interface, 184, 186 subtrees, 436–438 creating using XSLT, 354 CORBA (Common Object Response Broker XPath, 124, 127 Architecture), 10 comments, XML documents, 27–28 cosmos() method, 790 comments element, 540 count attribute, 363, 364, 365 Common EXSLT module, 378 count() function, 136 Common Object Response Broker Architecture country parameter, 648 (CORBA), 10 createAttribute() method, 860 comparing parsers. See parser comparisons createAttributeNS() method, 860 complex element content, 86–87 createCDATASection() method, 860 complex type definitions, WSDL, 680–681 createComment() method, 860 complex types, 73–76, 84–85 createDataObject() method, 824 complexContent element, 86–87 createDocument() method, 204, 856 complexType element, 74 createDocumentFragment() method, 860 compression option, 711 createDocumentType() method, 204, 856 concat() function, 137 createElement() method, 204–205, 860 conditional processing, XSLT, 358 createElementNS() method, 204–205, 860 conditional sections, DTDs, 68–70 createEntityReference() method, 860 connection_timeout option, 711 createProcessingInstruction() method, 860 constrained implementation, 459–460 CreateRatingUrl element, 653 constraining facets, 80–83 createTextNode() method, 209–210, 860 _construct() method, 853 creating resources, 636, 637. See also REST DOMAttr class, 862 (Representational State Transfer) DOMCdata class, 864 CRUD operations, 636 DOMComment class, 863 current() function, 374 DOMDocument class, 860 DOMDocumentFragment class, 859 ■D DOMElement class, 862 Data Access Service, SDO, 820–826 DOMEntityReference class, 865 data element, 102, 570 DOMProcessingInstruction class, 866 data encryption. See encryption ■INDEX 893

data exchange extensions, 166 default attributes, canonical XML, 450 data parameter default element content, 76–77 SoapHeader class constructor, 708, 869 default event handlers, 283–284, 302–303, 875 SoapParam class constructor, 709, 869 default mode, XMLSerializer class, 506 SoapVar class constructor, 707, 869 default namespaces data pattern, 114 canonical XML, 454, 458–459 data property, 863, 866 SimpleXML, 259 data storage and retrieval applications, 7–9 XML, 32, 34–35 data structures, UDDI. See UDDI (Universal XML schemas, 96 Description, Discovery, and Integration) XPath, 227 data-type attribute, 362 DEFAULTATTRS constant, 850 data type definitions, WSDL, 678–681 defaultHandler() method, 494 data types define element, 119 any types, allowing, 84 defines, RELAX NG, 117–119 attribute types, 62–66 DELETE (HTTP), 636, 637 base types, 73 delete_binding() function, 768 built-in types, 73 delete_business() function, 768 complex types, 73–76, 84–85 deleteData() method, 863 constraining facets, 80–83 delete_publisherAssertions() function, 768 derived types, 73, 80–83, 841–843 delete_service() function, 768

empty elements, 85 delete_tModel() function, 768 Find http://superindex.apress.com/ it faster at length, restricting, 81 deleting resources, 636, 637. See also REST matching regular expressions, 81 (Representational State Transfer) multiple types, allowing, 83–84 del.icio.us Web service, 785–786 PHP and XML-RPC data types, converting, department parameter, 652 610–611, 623 depth property, 321, 851 primitive types, 73, 839–841 derived types, 73, 80–83, 841–843 RELAX NG schemas, 102, 114 descendant axis, XPath, 128 simple types, 72–73, 83–84, 839–841 descendant nodes, XPath, 125 user-derived types, 73, 80–83 descendant-or-self axis, XPath, 128 WDDX, 568–569 description attribute, 758 XML schemas, 839–843 Description element, 652 databases, 7–9 description element datatypeLibrary attribute, 102 bindingTemplate structure, 759 Date construct, 545 businessEntity structure, 755 date type, 840 channel element, RSS 1.0, 525 dateTime element, 571 channel element, RSS 2.0, 536 dateTime type, 103, 569, 840 contact structure, 756 dateTime.iso8601 element, 598–599, 610–611 image element, RSS 2.0, 538 debugging. See also errors and error handling item element, RSS 1.0, 528 SOAP client calls, 722–723 item element, RSS 2.0, 538 XSLT, 376 textinput element, RSS 1.0, 528 decimal notation for characters, 15–16 textInput element, RSS 2.0, 538 decimal-separator attribute, 372 tModel structure, 761 decimal type, 840 deserialize() method, 590 decks, WML, 831 detached encryption, 477 declaration handlers, 281–283 detached signatures, 462 declaration separators, 59 detail element, 703–704 declarations detail parameter, 709, 710, 870 attribute lists. See attribute-list declarations DigestMethod element, 465 attributes. See attribute declarations DigestValue element, 465, 472 document type declarations, 19–20, 46–49 digit attribute, 373 element type declarations, 50–54 digital signatures, 460–461. See also encryption entity declarations, 29, 54–59 algorithms, 448–449 external subset declarations, 47–48 creating, 466–471 markup. See markup declarations detached signatures, 462 namespace. See namespace declarations enveloped signatures, 461 notation declarations, 66–67 enveloping signatures, 461–462 scope of. See scope generating references, 467–469 XML declaration, 18–19, 450 generating signatures, 470–471 decrypting data, 447–448, 484–489 hashing serialized XML, 443–445 deep copies of nodes, 355 message integrity, 442–443 default attribute, 79 verifying signatures, 471–474 894 ■INDEX

W3C specifications, 447 classes XML signature structure, 462–465 constructors, 220 digits in user-defined types, 82 extending core classes, 219–220, 226, 228 Director parameter, 664 methods, 221 disable-output-escaping attribute, 353 objects, classes, and interfaces, 183, 184, discard_authToken() function, 768, 774 186–187 discoverURLs element, 755–756 properties, 220–221 Distributed Component Object Model (DCOM), 10 registering, 885–887 distributed computing, 9 scope and object lifetime, 221–223, 226, distributed information systems. See Web services 885–887 div operator, 132 comments, 211 DOC constant, 317, 318, 850 creating and instantiating documents, 188–189 DOC_FRAGMENT constant, 317, 318, 850 document editing, 410, 415, 416 docstring key, 626 document element, 193–194 DOC_TYPE constant, 317, 318, 850 document fragments, creating, 211 DOCTYPE declarations, 19–20, 46–49 document navigation, 410, 414, 415 doctype property, 859 document node, 199, 203–204 doctype-public attribute, 382, 383, 384 domxml extension migration, 228–230 doctype-system attribute, 382, 383, 384 ease of use, 410, 416 document editing, parser comparisons, 410, element nodes, 204–206, 206–207 415–416 elements, 199–201, 217–218 document element, 18, 20 entity reference nodes, 211 in document type declarations, 46 exporting nodes from XMLReader, 328 retrieving using DOM extension, 193–194 external subsets and, 215 XPath element nodes, 125 handling encoded data, 188, 226 document encryption, 476 importing nodes from SimpleXML, 434, 435–436 document() function, 370 internal subsets and, 214–215 Document interface, 186 large document processing, 411, 412, 413 Document/literal message format, WSDL, 683–685 loading HTML data, 190–191 document navigation, parser comparisons, 410, loading XML data, 189–190, 193 413–415 locating elements, 431–432, 433 document nodes, 159, 203–204 namespace declarations, 203 Document Object Model. See DOM (Document namespace support, 410, 418–419 Object Model) namespaces, registering, 218–219, 227 document tree, 20 navigating between nodes, 196–201 document type declarations (DOCTYPE), 19–20, node information, 194–196, 217 46–49. See also markup declarations node types, 181–182, 194 documentElement property, 859 objects, creating and instantiating, 187–188, documents 885–887 HTML. See HTML documents optimizing, 426–427, 431–432, 433 RSS, 391–392 PAD template (example), 230–234 well-formed documents, 45 parent nodes, 198–199 XHTML, 516–519 processing instruction nodes, 211 XML. See XML documents removing nodes, 212–213, 225 DocumentType interface, 187 replacing nodes, 213 documentURI property, 859 saving HTML data, 192 doGetCachedPage() function, 746–747 saving XML data, 191 doGoogleSearch() function, 746, 747–748 sibling nodes, 198 DOM (Document Object Model), 9, 14, 181. SimpleXML interoperability, 250, 253, 255, See also DOM extension; DOM objects 434–436 creating feeds, 551–560 subtrees, 197 node types, 181–182, 194 system resource usage, 410, 411, 412, 413 Services_Webservice package, 797–802 text nodes, 209–210 tree representation of documents, 182 troubleshooting, 223–228 XML_Tree package, 498–501 validation DOM extension, 165, 185–188, 854–855, 883–887. using DTDs, 214–215 See also DOM (Document Object Model) using RELAX NG schemas, 216 attribute nodes, 207–209 using XML schemas, 215–216 attributes, 201–203, 883–884 XMLReader interoperability, 436–438 CDATA section nodes, 211 XML_Tree package, 498–501 child nodes, 196–197 XPath support, 216–219 choosing parsers, 424–425, 426 XSL template (example), 235–237 ■INDEX 895

DOM objects. See also DOM (Document Object double element, 597 Model) double type, 840 constructors, 220 DTDs (Document Type Definitions), 3, 14. creating and instantiating, 187–188 See also validation extending core classes, 219–220, 226, 228, adding manually, 227 885–887 attribute ID definitions, 36–38, 64 in PHP sessions, 224–225 attribute-list declarations, 59–66 methods, 221 conditional sections, 68–70 nodes vs. objects, 221–223 document type declarations, 19–20, 46–49 objects, classes, and interfaces, 183, 184, element type declarations, 50–54 186–187, 885–887 entity declarations, 29, 54–59 properties, 220–221 entity references, 28–29 scope and object lifetime, 221–223, 226 external subsets, 46–48 serialization, 224–225 in canonical XML, 450 DOM parser, SAX example code, 306–310 internal subsets, 48–49 DOMAttr class, 187, 228, 861–862 markup declarations. See markup declarations DOMCdata class, 864 namespaces and, 35 DOMCDATASection class, 187, 228 notation declarations, 66–67 DOMCharacterData class, 186, 210–211, 863 parsing, 512–516 DOMComment class, 187, 863 schemas vs., 71, 90

DOMDocument class, 186, 188–192, 203–204, standalone declaration and, 19 Find http://superindex.apress.com/ it faster at 859–861. See also tree, DOM validation DOMDocument object, 392–393 within DOM extension, 214–215 DOMDocumentFragment class, 186, 211, 212, 859 XML_DTD package, 512, 515 DOMDocumentType class, 187, 864–865 within XMLReader, 333 domdtd class, 228 Dublin Core module, 530–531 DOMElement class, 187, 862 duration type, 840 DOMEntity class, 187, 865 DOMEntityReference class, 187, 228, 865 ■E DOMException class, 186, 856 E-Commerce Service, Amazon (ECS), 13, 660, DOMException interface, 184 781–785 DOM_HIERARCHY_REQUEST_ERR constant, 855 ease of use, parsers. See parser comparisons DOMImplementation class, 185, 186, 203–204, 856 eBay Web services, 13, 736 dom_import_simplexml() function authentication, 743 DOM_INDEX_SIZE_ERR constant, 855 registration and setup, 736–737 DOM_INUSE_ATTRIBUTE_ERR constant, 855 remote procedure calls, 743–744 DOM_INVALID_ACCESS_ERR constant, 855 requests, 741 DOM_INVALID_CHARACTER_ERR constant, 855 responses, 741–742 DOM_INVALID_MODIFICATION_ERR constant, Services_Ebay package, 786 855 SOAP client implementation, 737–740 DOM_INVALID_STATE_ERR constant, 855 eBayAuth class, 743 DOMNamedNodeMap class, 186, 201–202, 857 ebay.ini file, 738–739 DOM_NAMESPACE_ERR constant, 855 ebaySession object, 739–740 DOMNameSpaceNode class, 186 eBaySOAP class, 741 domnamespacenode class, 228 efficiency of parsers. See parser comparisons DOM_NO_DATA_ALLOWED_ERR constant, 855 EJSE, 793 DOMNode class, 186, 194–196, 857 ELEMENT constant, 317, 318, 850 DOMNodeList class, 186, 196–197, 856 element content, 21 DOM_NO_MODIFICATION_ALLOWED_ERR

default namespaces and, 32, 34–35, 227 email element, 545, 756 element handlers, 274–275 empty attribute values, 25 element hierarchy, 22–24 empty element content, 112–113 element type declarations, 50–54 empty-element tags, 21–22 empty-element tags, 21–22 empty elements, 85, 450 identifying uniquely, 36–38 empty namespace declarations, 454 in DOM, 199–201, 226–227 empty pattern, 106 in RELAX NG. See elements (RELAX NG) EMPTY value, 50, 84 in SimpleXML. See elements (SimpleXML) enabled attribute, 87 in XML schemas. See elements (XML schemas) enclosure element, 540–541 in XSL and XSLT. See elements (XSL, XSLT) encoding and encoded data, 19 namespaces and, 31, 32 Base64 encoding, 27, 67 nesting of, 23–24 binary data, WDDX, 576 referencing from other elements, 38–40 byte order mark (BOM), 169 elements (RELAX NG) detecting document encoding, 168–170 declaring, 101–103, 111–113 encoding conversions, 171–172, 293–294 defining allowable content, 112–113 encoding declaration, 19, 169–170 disallowing, 105 encryption, 293–294 empty content, 112 handling encoded data, 67, 188, 226 mixed content, 107–108, 111–112 images, XML documents, 65–66 naming elements, 104–105 in canonical XML, 450 patterns. See patterns in libxml2, 168, 170–172 elements (SimpleXML) in XMLWriter, 816 accessing by index, 245–246 SAX parser options, 273 accessing by name, 242–243 target encoding, xml extension, 300 accessing child elements, 244, 245–246 encoding attribute accessing element content, 243–244 binary element, WDDX, 576 accessing namespaced elements, 258–260 xi:include element, 153 accessing unknown elements, 246–247, 250 xsl:output element, 382, 383, 387 collections, iterating, 245–246, 246–247 encoding declaration, 19, 169–170 modifying child elements, 252–253 encoding element, 534 modifying subtrees, 252 encoding option, 613, 711 modifying text content, 251–252 encoding parameter, 707, 724, 869 names of, determining, 247–250 encoding property, 859 namespaces and, 258–260, 879–883 encodingStyle attribute, 698 removing from trees, 253–255 EncryptedData element, 478, 481, 483 replacing subtrees, 253 EncryptedKey element, 481 elements (XML schemas). See also schemas, XML encryption annotation elements, 88 algorithms, 448–449 complex element content, 86–87 canonical XML, 482 complex types, 73–76, 84–85 character data encryption, 476 declaring, 73, 74–76 decrypting data, 447–448, 484–489 default content, 76–77 detached encryption, 477 element groups, 78–79 document encryption, 476 element name substitutions, 77–78 element encryption, 475 empty elements, 85 encrypting data, 446–447, 480–484 fixed content, 76–77 enveloping encryption, 477 global declarations, 95 mixed content encryption, 475–476 local declarations, 95 super encryption, 476–477 mixed content, 85–86 W3C specifications, 447 namespaces and, 94–100 XML encryption structure, 477–480 notation elements, 87–88 EncryptionMethod element, 479, 483 NULL-valued elements, 77 end-point() function, 151 qualified local declarations, 95–97 end tags, 21, 23–24 schema element, 72 endAttribute() method, 872 simple types, 72–73, 83–84 endCdata() method, 872 unqualified local declarations, 94–95 endComment() method, 872 user-defined types, 80–83 endDocument() method, 814, 873 elements (XSL, XSLT) endDtd() method, 873 creating, 350–351 endDtdElement() method, 873 EXSLT extension elements, 377–378 END_ELEMENT constant, 318, 850 matching, 343 endElement() method, 814, 872 selecting for processing, 346–347 END_ENTITY constant, 318, 850 ■INDEX 897

endHandler() method, 494 declaration handlers, 281–283 endPi() method, 872 default handler, 283–284, 302–303 entities, 54–55. See also entity declarations; entity element handlers, 274–275 references external entity reference handlers, 280–281, general entities, 29, 55–57 305–306 in SAX parser, 278–279 namespace declaration handlers, 297 in SGML, 3 object methods as handlers, 297–300 parameter entities, 57–59 processing instruction handlers, 279 parsed entities, 55–56 event mode, XML_Parser, 495–496 unparsed entities, 57, 374–375 every quantifier, 161 entities property, 864 exactNameMatch option, 766 ENTITY, ENTITIES types, 65–66, 843 except pattern, 104–105 ENTITY constant, 317, 318, 850 exceptions option, 711 entity declarations, 29, 54–59 exceptNameClass pattern, 104–105 Entity interface, 187 exclusive XML canonicalization, 456–457, 459–460 entity references, 55 expand() method, 328, 436–438, 852 ENTITY, ENTITIES attribute types, 65–66 expanded names, XPath nodes, 124 entity errors, 227 expressions external entity reference handlers, 280–281, attribute value templates, 349–350 305–306 in markup declarations, 49–50

in attribute-list declarations, 62–63 XPath. See expressions (XPath) Find http://superindex.apress.com/ it faster at in canonical XML, 450, 455 XPath 2.0, 159–161 in SAX parser, 278–279, 280–281 XPointer, 147–148 in XML documents, 28–29 expressions (XPath) optimizing memory usage, 426–427 abbreviated syntax, 131–132 for restricted characters, 17 axes, 127–128 ENTITY_REF constant, 317, 318, 850 calculations in, 146 EntityReference interface, 187 complex expressions, 141–146 entityrefHandler() method, 494 equivalent XPointer expressions, 147 entry documents, Atom, 543, 549–550 filtering node sets, 133–134 entry element, 543, 549–550, 557 name tests, 128–130 enumerated attribute types, 63–64 namespaces and, 141–143, 148 enumeration element, 80 node type tests, 130 Envelope element, 698 optimizing, 138–139 enveloped signatures, 461 value comparisons, 135–136, 144–145 enveloping encryption, 477 XPath functions, 136–138, 144–145, 146 enveloping signatures, 461–462 XPath operators, 130 epilog, XML documents, 20 exsl:document element, 378 Error structure, Amazon Web services, 661–663 EXSLT modules, 377–380, 395 errors and error handling. See also debugging; extending classes faults in DOM extension, 219–220, 226, 228 Amazon Web services, 661–663 in SimpleXML extension, 257–258 DOMException interface, 184, 186 extends keyword, 219–220 entity errors, 227 Extensible Business Reporting Language (XBRL), 6 failed XIncludes, 155–156 extension element, 87 failed XPointer expressions, 156–157 extension-element-prefixes attribute, 377–378 fallback capabilities, XSLT, 380 extensions, PHP 5. See XML extensions, PHP in XML-RPC, 607, 614, 618 external content, including. See XInclude libxml2-derived errors, 177–179 external entities, 47, 57, 65–66 SOAP header entries, 700–701 external entity reference handlers, 280–281, using SAX, 292–293 305–306 validation errors, 177 external patterns, 119–121 WSDL, 687, 689 external subsets, 46–48, 58, 68–70 Yahoo Web services, 660 externalRef element, 119–121 Errors structure, Amazon Web services, 661–663 escaping characters, 146 ■F escaping option, 613 facets, constraining, 80–83 evaluate() method, 216, 217–218, 856 factory() function, 803 evaluating node sets. See expressions, XPath fallback capabilities, XSLT, 380 event-based parsing, 165, 269–270. See also SAX false() function, 138 (Simple API for XML) Fault element, 701–704 event handlers, SAX fault element, 607, 618, 686, 687, 693, 694 character data handlers, 275–279, 301 fault() method, 871 898 ■INDEX

fault structures, XML-RPC, 607, 614, 618 format attribute, 365 faultactor element, 703, 709 format element, 533 faultactor parameter, 870 format-number() function, 372–373 faultcode element, 702 format parameter, 648 faultCode() method, 626 formatFile() method, 503 faultcode parameter, 709, 870 formatOutput property, 859 faultname parameter, 710, 870 formatString() method, 503–504 faults. See also errors and error handling formatted numbers, XSLT results tree, 362–366 SOAP, 701–704, 709–710, 729–730, 870 formatting XML documents, 23–24, 502–504, WSDL, 687, 693 816–817 XML-RPC, 607, 618 forms, RSS, 528–529, 538–539 faultstring element, 702–703 fractionDigits element, 82 faultString() method, 626 from attribute, 363, 364, 365 faultstring parameter, 709, 870 fromKey element, 764 feed documents, Atom, 542–543, 547–549 func mode, XML_Parser, 495–496 feed element, 543, 546, 547–549, 552, 557 func:function element, 378 Feed Validator, 521 func:result element, 378 feeds and feed technologies, 521–522, 550–551 function() function, 397–399 Atom. See Atom function key, 626 creating feeds using DOM, 551–560 functions. See also methods; names of specific parser using SimpleXML (example), 560–561 functions RSS 1.0. See RSS 1.0 (RDF Site Summary) user-defined, 378–380 RSS 2.0. See RSS 2.0 (Really Simple Syndication) XPath, 136–138, 144–145, 146 Field element, 655 XPointer, 149–151 field element, 574–576 Functions EXSLT module, 378–380 Fielding, Roy, 633 functionString() function, 397–399 fieldNames attribute, 574–575 file data, parsing, 287 ■G file property, 178, 847 gDay type, 841 file security support, PHP 5, 175–176 general entities, 29, 55–59. See also parameter filter option, 788 entities filter parameter, 748 generate-id() function, 375 filtering, XPath expressions generator element, 548 abbreviated syntax, 131–132 GET (HTTP), 636–637 axes, 127–128 get_assertionStatusReport() function, 768 calculations, 146 getAttribute() method, 202, 329, 331, 851, 862 filtering node sets, 133–134 getAttributeNo() method, 851 node tests, 128–130 getAttributeNode() method, 202, 862 numeric comparisons, 136 getAttributeNodeNS() method, 202, 862 optimizing expressions, 138–139 getAttributeNS() method, 202, 331, 862 predicates, 130 getAttributeNs() method, 851 string comparisons, 135 getAttributes() method, 514 value comparisons, 135–136, 144–145 get_authToken() function, 768, 773 XPath functions, 136–138 get_bindingDetail() function, 766 XPath operators, 132 get_businessDetail() function, 766 find_binding() function, 765 get_businessDetailExt() function, 766 find_business() function, 765 getCachedPage() method, 787 find_relatedBusiness() function, 765 getChannelInfo() method, 564 find_service() function, 766 getChildren() method, 514 find_tModel() function, 766 getContent() method, 515 firstChild property, 197, 857 getDocNamespaces() method, 854, 879–891 firstResultPosition attribute, 647 getDTDRegex() method, 515 fixed attribute, 79 getElement() method, 500 #FIXED attribute default, 61 getElementByID() method, 226–227, 860 fixed element content, 76–77 getElementsByTagName() method, 199–200, 861, flags, PHP parser options, 173–174 862 Flickr, 646 getElementsByTagNameNS() method, 199, 201, float type, 840 861, 862 floor() function, 138 getForecast() method, 796 flush() method, 814, 817–818, 872 getFunctions() method, 871 following axis, XPath, 128 _getFunctions() method, 712, 870 following-sibling axis, XPath, 128 getImages() method, 564 form attribute, 96–97 getInfo() method, 790 ■INDEX 899

getItems() method, 564 hasAttributes property, 321, 851 _getLastRequest() method, 722, 870 hasChildNodes() method, 196–197, 858 _getLastRequestHeaders() method, 722, 870 hasExsltSupport() method, 390, 395, 866 _getLastResponse() method, 722, 870 hasFeature() method, 856 _getLastResponseHeaders() method, 722, 870 hashing serialized XML, 443–445 getLocation() method, 794 hasValue property, 321, 851 getMessage() method, 515 HEAD (HTTP), 636 getNamedItem() method, 857 header element, 570, 699 getNamedItemNS() method, 857 header entries, SOAP getNamespaces() method, 854, 879–881 Header element, 699–701 get_object_vars() method, PHP, 247–248 in SOAP clients, 718–719 getParameter() method, 390, 393, 394–395, 866 in SOAP servers, 730–732 getParserProperty() method, 316–317, 851 SoapHeader class, 708 getPcreRegex() method, 515 headerfault parameter, 710, 870 get_publisherAssertions() function, 768 headers, 601–602, 605 get_registeredInfo() function, 768 height element, 538 getSerializedData() method, 509 here() function, 151 get_serviceDetail() function, 766 hexadecimal notation for characters, 15–16 getStructure() method, 565 hexBinary type, 841 getTextinputs() method, 564 highestprice parameter, 652 get_tModelDetail() function, 766 history of XML, 2–4 Find http://superindex.apress.com/ it faster at _getTypes() method, 712, 870 HMAC hash, 444 getUnserializedData() method, 511 hostingRedirector element, 760 getUser() function, 741 href attribute getUserRequestType parameter, 741 link element, Atom, 546 getWeather() method, 795 xi:include element, 152 global scope of declarations, 89–91, 93 XLink, 158 GlobalWeather, 793 hreflang attribute, 546 GML (Generalized Markup Language), 2 HTML documents gMonth type, 841 parsing, 504–506 gMonthDay type, 841 transforming XML data, 356–357 Goldfarb, Charles F., 2 using XSLT processor, 391–392 Google Web services, 12–13 HTML (Hypertext Markup Language), 3, 22–24 AdWords API service, 744 loading in DOM trees, 190–191 cached pages, retrieving, 787 outputting to XSLT trees, 385–387 checking spelling, 787 html value, Text construct, 544 doGetCachedPage() function, 746–747 HTTP DELETE, 636, 637 doGoogleSearch() function, 746, 747–748 HTTP GET, 636–637 doSpellingSuggestion() function, 746–747 HTTP HEAD, 636 GoogleSearchResult structure, 745, 748–750 HTTP POST registration and setup, 744 in REST architecture, 636, 637 search services, 744–750, 788–789 using SOAP, 704 Services_Google package, 786–789 XML-RPC request headers, 601–602 GoogleSearchResult structure, 745, 748–750 HTTP PUT, 636, 637 grammar element, 117–119, 120 HTTP requests, using SOAP, 704 grammars, 46, 49–50, 57–59 HTTP responses, using SOAP, 705 group element, 78–79 group pattern, 106 ■I grouping-separator attribute, 363, 372 i4 element, 597 grouping-size attribute, 363 IANA (Internet Assigned Numbers Authority), 19 groups and grouping, 78–79 icon element, 548 guid element, 541 iconv extension, 171–172 gYear type, 841 ID attributes, 36–38, 40–41, 64, 226–227 gYearMonth type, 841 id element, 547, 549 id() function, 136, 155 ■H id specification, 36, 40–41 handle() method, 729, 871 ID type, 73, 843 handleElement() method, 497 identifierBag element, 755, 762 handlers, event-based parsing, 165 IDREF attribute, 38–39, 64 handlers, registering, 494, 505 IDREF type, 73, 843 hasAttribute() method, 862 IDREFS attribute, 39–40, 64 hasAttributeNS() method, 862 IDREFS type, 843 hasAttributes() method, 201, 858 IDs, 370–372, 375, 389 900 ■INDEX

ie parameter, 748 isWhitespaceInElementContent() method, 864 if/then/else expressions, 160–161 item element IGNORE blocks, 68–70 channel element, RSS 2.0, 539–541 image element Content module, 533 channel element, RSS 2.0, 537, 538 RDF element, RSS 1.0, 527–528, 530, 556 items element, RSS 1.0, 526 item() method, 856, 857 RDF element, RSS 1.0, 526–527, 530 ItemPage parameter, 664 images items element, 524, 532–533, 555 adding to XML documents, 65–66 itemType attribute, 83 in RSS feeds, 526–527, 538 iterating collections notation elements, 87–88 of attributes, 201–202 imageType attribute, 87 of nodes, 196–197, 225 implementation property, 859 of XSLT node sets, 358–360, 360–362, 406–407 #IMPLIED attribute default, 60–61 import element, 91, 97–100 ■J importNode() method, 861 JavaScript (Ajax), 826–830 importStylesheet() method, 390–391, 866 INCLUDE blocks, 68–70 ■K include element, 91–93 key() function, 370–372 including conditional DTD sections, 68–70 key parameter, 748 inclusive canonical XML, 457. See also canonical keyedReference element, 764 XML KeyInfo element, 465, 479, 481, 485, 487 InclusiveNamespaces PrefixList parameter, keyInfo() method, 790 457–459 keys indent attribute, 381, 383 HMAC hash, 444 indent option, 502 XML encryption, 479, 481, 485 indentation, 23–24 XML signatures, 465 indentXML() method, 518 XSLT, 370–372, 389 infinity attribute, 373 Keywords parameter, 664, 665 inline style sheets, 343 input element, 686, 689, 693 ■ input settings, XML_Parser, 495 L Inquiry API, UDDI, 765–767, 769–772 label attribute, 546 insertBefore() method, 206, 207, 209–210, 858 lang attribute insertData() method, 863 Atom elements, 543 instructions in schemas, 88 XML, 42 int element, 597 xsl:sort element, 362 int type, 842 lang() function, 138 integer type, 842 language option, 788 integrity, 460. See also digital signatures language parameter, 648 interleave pattern, 108–109 language type, 842 intermediaries, 700 languages, specifying, 42 internal parsed entities, 55–56 large document processing internal subsets, 48–49, 58 breaking into smaller documents, 426–427, internalSubset property, 865 436–438 IRIs (internationalized resource identifiers), 543 DOM extension, 411, 412, 413 isDefault property, 321, 851 optimizing memory usage, 426–427 isDefaultNamespace() method, 858 optimizing performance, 429–433 isElementContentWhitespace() method, 864 parser comparisons, 411–413 isEmptyElement property, 321 SimpleXML, 411, 412, 413 is_final parameter, 285–287 streaming parsers, 411, 413 isId() method, 862 tree-based parsers, 411, 413 ISO-8859-1, ISO-2022-JP encodings, 19 xml extension, 412, 413 ISO 10646 character set, 15 XMLReader, 413 ISO (International Organization for last() function, 136 Standardization), 14 lastChild property, 197, 857 isSameNode() method, 199, 858 length attribute, 546, 572 is_soap_fault() function, 868 length element, 81 isSupported() method, 858 length property, 863 isValid() method level attribute, 363, 364, 365 xml extension, 333, 334 level key, array structures, 289 XML_DTD, 515, 519 level property, 178, 847 XMLReader, 851 li element, 525, 555, 556 ■INDEX 901

libraries in XML documents, 16 determining library version, 172–173 migrating to PHP 5, 301 libxml2. See libxml2 library line number, retrieving using SAX, 291–292 libxslt. See libxslt library line property, 178, 847 PEAR. See PEAR linebreak option, 502 supported versions, 163–164 link element libxml extension, 167–168, 845 Atom, 545, 557 libxml2 library channel element, RSS 1.0, 525 enabling and disabling, 167 channel element, RSS 2.0, 536 encoding conversions, 171–172 entry element, Atom, 549 errors, retrieving, 293 feed element, Atom, 548 internal document encoding, 170–172 image element, RSS 1.0, 527 library location, 167–168 image element, RSS 2.0, 538 library version, 172–173 item element, RSS 1.0, 528 libxml2-derived errors, 177–179 item element, RSS 2.0, 539 supported versions, 163–164 textinput element, RSS 1.0, 528 libxml_clear_errors() function, 178–179, 846 textInput element, RSS 2.0, 538 LIBXML_COMPACT constant, 846 links between resources (XLink), 157–159 LIBXML_DOTTED_VERSION constant, 845 list pattern, 110–111 LIBXML_DTDATTR option, 173, 450, 845 list type, 83

LIBXML_DTDLOAD constant, 845 literal values, 349–350 Find http://superindex.apress.com/ it faster at LIBXML_DTDLOAD option, 173, 450 load() method, 189–190, 428, 861 LIBXML_DTDVALID constant, 845 load time of large documents, 429–430 LIBXML_DTDVALID option, 173 LOADDTD constant, 850 LIBXML_ERR_ERROR constant, 847 loadHTML() method, 191, 861 LIBXML_ERR_FATAL constant, 847 loadHTMLFile() method, 191, 861 LIBXML_ERR_NONE constant, 847 loading documents LibXMLError object, 178–179 HTML data, 190–191 LIBXML_ERR_WARNING constant, 847 XML data, 189–190 libxml_get_errors() function, 178–179, 846 loadXML() method, 189–190, 861 libxml_get_last_error() function, 178–179, 293, 846 local-name() function, 137 LIBXML_NOBLANKS constant, 846 local scope of declarations, 89–91, 93 LIBXML_NOBLANKS option, 173 local_cert option, 711 LIBXML_NOCDATA constant, 846 localName property, 321, 851, 858 LIBXML_NOCDATA option, 173, 450 location, XPointer, 149 LIBXML_NOEMPTYTAG constant, 846 location option, 711, 714–715 LIBXML_NOENT constant, 845 location paths. See paths, XPath LIBXML_NOENT option, 173, 450 location set, XPointer, 149 LIBXML_NOERROR constant, 846 location type, 149 LIBXML_NOERROR option, 173 login option, 711 LIBXML_NONET constant, 846 logo element, 548 LIBXML_NONET option, 173 long type, 842 LIBXML_NOWARNING constant, 846 lookupNamespace() method, 851 LIBXML_NOWARNING option, 173 lookupNamespaceURI() method, 858 LIBXML_NOXMLDECL constant, 846 lookupPrefix() method, 858 LIBXML_NSCLEAN constant, 846 Lorie, Ray, 2 LIBXML_NSCLEAN option, 173 lowercase characters, 17–18 libxml_set_streams_context() function, 176, 846 lowestprice parameter, 652 libxml_use_internal_errors() function, 178–179, lr parameter, 748 376, 846 LIBXML_VERSION constant, 845 ■M LIBXML_XINCLUDE constant, 846 Manufacturer parameter, 664 LIBXML_XINCLUDE option, 173 markup, 16–17, 26–27 libxslt library, 163–164, 389 markup declarations license parameter, 648 attribute-list declarations, 59–66 lifetime of objects, 221–223, 226 attribute types, 62–66 limit option, 788 element type declarations, 50–54 line feed character entity declarations, 54–59 formatting XML documents, 23–24 notation declarations, 66–67 in canonical XML, 450, 455 wildcards, 49–50 in SAX parser, 277, 278 markup language, 2 in user-derived types, 81–82 markup tags, 3 902 ■INDEX

marshaling, 595. See also WDDX (Web Distributed minOccurs attribute, 74, 75, 78, 89–90 Data Exchange); XML-RPC minus-sign attribute, 373 match attribute, 343, 371 Misc* section, 20 Math EXSLT module, 377 mixed attribute, 86, 87 Mathematical Markup Language (MathML), 5 mixed content model, 52–54 maxCommentLine option, 503 mixed element content maxExclusive element, 82 RELAX NG schemas, 107–108, 111–112 MaximumPrice parameter, 664 XML schemas, 85–86 maxInclusive element, 82 mixed pattern, 106 maxLength element, 81 mod operator, 132 maxOccurs attribute, 74, 75, 78, 89–90 mode attribute, 344, 347 MaxRating element, 653 ModificationDate element, 650 maxResults option, 788 modifying resources, 636, 637. See also REST maxResults parameter, 748 (Representational State Transfer) mbstring extension, 171–172 modules, RSS mcrypt library, 446–448 Content module, 532–534 MD5 hash, 443 Dublin Core module, 530–531 media-type attribute, 382, 383, 386, 387 Syndication module, 531–532 member element, 600 Mosher, Ed, 2 memberTypes attribute, 84 moveToAttribute() method, 326, 327, 331, 851 memory usage moveToAttributeNo() method, 326, 327, 851 DOM extension, 410, 411, 412, 413 moveToAttributeNs() method, 326, 331, 851 large document processing, 426–427 moveToElement() method, 327, 852 multiple document processing, 427–429 moveToFirstAttribute() method, 327 parser comparisons, 410, 411 moveToFirstElement() method, 852 SimpleXML, 410, 411, 412, 413 moveToNextAttribute() method, 327 streaming parsers, 411, 413 moveToNextElement() method, 852 tree-based parsers, 411, 413 multilineTags option, 503, 504 xml extension, 410, 412, 413 multiple documents, processing, 427–429 XMLReader, 410, 413 multiple formats, publishing to, 6 Merchant element, 655, 656 mustUnderstand attribute, 700–701, 708 merchantid parameter, 652, 656 MustUnderstand fault code, SOAP, 702 MergeCart parameter, 668 mustUnderstand parameter, 869 message attribute, 694 message authentication, 460. See also digital ■N signatures name attribute message definitions, WSDL, 681–685 businessService structure, 758 message element, 681 RELAX NG schemas, 105, 113 message integrity template element, 343 canonical XML. See canonical XML XML schemas, 73 encryption. See encryption xsl:decimal-format element, 372 hashing serialized XML, 443–445 xsl:element element, 350 signatures. See digital signatures xsl:key element, 371 message property, 178, 847 xsl:variable, xsl:param elements, 366 messages, debugging XSLT, 376 name element metalanguages, 2 businessEntity structure, 755 method attribute, 381 Person construct, 545 methodCall element, 603–604 textinput element, RSS 1.0, 528 methodName element, 603 textInput element, RSS 2.0, 538 methodResponse element, 606, 618 tModel structure, 761 methods. See also functions; names of specific XML-RPC, 600 methods name() function, 137 domxml/DOM extension migration, 228–230 name parameter, 708, 709, 869 as event handlers, 297–300 name property, 321, 851, 861, 864 extending DOM classes, 221 name tests, XPath expressions, 128–130 mhash extension, 444 Name type, 843 migrating to PHP 5, 300–306 name/value pairs, 24–25 MIME types, 66–67 nameClass pattern, 104–105 MimeType element, 650 named attribute groups, 79 minExclusive element, 82 named attribute sets, 352–353 MinimumPrice parameter, 664 named element groups, 78–79 minInclusive element, 82 named elements, 3 minLength element, 81 named patterns, 117–119 ■INDEX 903

NameNodeMap interface, 184, 186 registering, 218–219, 227, 261 names. See also namespaces reserved prefixes, 33 attribute ID names, 37 SAX parser and, 294–297 attribute names, 24–25, 104–105 scope of, 33–35 attribute uniqueness, 35–36 sorting for canonical XML, 451–453 characters allowed in, 16 specifying in schemas, 72 DOM extension node names, 194–195 tips for using, 35 element name substitutions, 77–78 unqualified local declarations, 94–95 element names, 21, 104–105, 351 unqualified names, 115–116 namespaces and, 35–36 user-defined functions, EXSLT, 378–380 QNames, 31, 32, 35 W3C XML Schemas namespace, 72 reserved names, 16 xsd prefix, 72 scope of declarations and, 90, 93 namespaceURI property, 321, 330–331, 851, 858 XPath node names, 124 NaN attribute, 373 namespace attribute, 99, 351 National Weather Service, 793 namespace-aware parsers, 209, 296, 309 native XML databases (NXDs), 8–9 namespace declaration handlers, 297 NCName type, 843 namespace declarations NCName:* XPath name test, 130 canonical XML, 450, 454 NDATA keyword, 57 DOM extension, 203 negativeInteger type, 842

SAX parser, 295, 297 nesting Find http://superindex.apress.com/ it faster at XML schemas, 76 conditional sections in DTDs, 70 namespace nodes elements, 23–24 canonical XML, 454–455 next() method, 320, 323–325, 329, 431, 852 XPath, 124, 126–127 nextSibling property, 198, 857 namespace parameter, 708, 869 nillable attribute, 77 namespace-uri() function, 137 NMTOKEN, NMTOKENS types, 64–65, 843. namespace URIs, 330–331 See also CDATA type namespace XPath axis, 128 Node interface, 182, 186 namespaced schemas, 94–100 node objects and interfaces namespaces, 29–30 CharacterData interface, 184, 186 attribute uniqueness, 35–36 DOMException interface, 184, 186 combining multiple schemas, 91–93, 94–97, DOMImplementation interface, 185, 186, 98–100 203–204 declarations. See namespace declarations NameNodeMap interface, 184, 186, 225 default. See default namespaces Node interface, 182, 186 defining, 31 Node objects in DOM tree, 183 element nodes, within namespaces, 205, 206 NodeList interface, 184, 186 elements in specific namespaces, 201 node order elements in transformed trees, 351 canonical XML, 450, 451–453 in DOM extension, 218–219, 227, 418–419 XSLT, 360–362, 406–407 in DOM parser example, 308 node sets (XPath) in exclusive XML canonicalization, 457–459 axes, 127–128 in RELAX NG schemas, 101, 115–117 filtering, 133–134 in SimpleXML extension, 258–260, 261, 419, location paths, 127 879–883 name tests, 128–130 in xml extension, 417–418 node set functions, 136–137 in XMLReader, 312–313, 328–333, 418 node type tests, 130 in XMLWriter, 818–819 predicates, 130 in XPath expressions, 129, 130, 141–143 node sets (XSLT) in XPath node names, 124 conditional processing, 358–360 in XPointer expressions, 148 containing current node only, 374 in XSL templates, 237 external documents, accessing, 370 named patterns and, 118–119 repetitive processing, 358 namespace collisions, 31 sorting, 360–362, 406–407 namespace declaration handlers, 297 node tests, XPath expressions, 128–130, 131–132 namespace support, parser comparisons, 410, node type constants, 317–319, 850 417–419 node type tests, 130 namespaced schemas, 94–100 node types, DOM, 181–182, 194. See also DOM naming, 33 (Document Object Model) PHP function calls and, 397 NodeList interface, 184, 186 qualified local declarations, 95–97 node_name parameter, 707, 869 qualified names, 116–117 nodeName property, 194–195, 857 904 ■INDEX

node_namespace parameter, 707, 869 XPath functions, 136–138, 144–145, 146 nodes, UDDI registries, 752 XPath operators, 130 nodes (DOM) nodes (XSL, XSLT) attribute nodes, 207–209 matching in templates, 343 attributes, 201–203 selecting for processing, 346–347 CDATA section nodes, 211 nodeType property, 194, 321, 851, 857 child nodes, 196–197 nodeValue property, 195, 857 comments, 211 non-normative exclusive XML canonicalization document fragments, 211 implementation, 459–460 document node, 199, 203–204 NONE constant, 317, 318, 850 DOM node types, 181–182, 194 nonNegativeInteger type, 842 element nodes, 204–207 nonPositiveInteger type, 842 elements normalize() method, DOMNode class, 858 accessing by ID, 226–227 normalize-space() function, 137 accessing by name, 199–201 normalizeComments option, 503, 504 accessing using XPath, 217–218 normalizeDocument() method, 861 entity reference nodes, 211 normalizedString type, 842 in DOM tree, 182–183 not() function, 138 iterating collections, 196–197, 225 NOTATION constant, 317, 318, 850 Node interface, 182 Notation interface, 187 node name, 194–195 NOTATION type, 64, 67, 841 node objects, 183 notationHandler() method, 494 node type, 194 notationName property, 865 node value, 195 notations, 57, 64, 66–67, 281–283 objects, DOM, vs. nodes, 221–223 notations property, 865 parent nodes, 198–199 notes (annotation elements), 88. See also processing instruction nodes, 211 comments properties, 194–196 notification operation, WSDL, 698–699 removing from tree, 212–213, 225 ns attribute, 115–116 replacing, 213 null element, 571 retrieving using XPath, 217 null type, 569 sibling nodes, 198 NULL value, 77 text nodes, 209–210 number element, 571 nodes (in transformed trees) number() function, 137, 138 attribute value templates, 349–350 number type, 569 attributes, 351–352 numeric values comment nodes, 354 formatted numbers, XSLT, 362–366, 372 copying nodes, 354–355 numeric comparisons, XPath, 136 current node, retrieving, 374 in user-defined types, 82 elements, 350–351 NumRatings element, 653 named attribute sets, 352–353 NXDs (native XML databases), 8–9 node sets conditional processing, 358–360 ■O repetitive processing, 358 OASIS (Organization for the Advancement of sorting, 360–362 Structured Information Standards), 14 processing instruction nodes, 353–354 Object element, 465 text nodes, 353, 356 object handlers, XML_Parser, 496–497 nodes (XPath) object lifetime, 221–223, 226 axes, 127–128 object methods as event handlers, 297–300 calculations in expressions, 146 object-oriented interface, xml extension, 493–498 complex XPath expressions, 141–146 object type definitions, WSDL, 679–680 context nodes, 127, 134 objects, DOM equivalent XPointer expressions, 147 constructors, 220 filtering node sets, 133–134 creating and instantiating, 187–188 location paths, 127–132 extending core classes, 219–220, 226, 228, node tests, 128–130 885–887 node type tests, 130 in PHP sessions, 224–225 node types, 125–127 methods, 221 optimizing XPath expressions, 138–139 nodes vs. objects, 221–223 predicates, 130 objects, classes, and interfaces, 183, 184, value comparisons, 135–136, 144–145 186–187, 885–887 XPath data model, 124–125 properties, 220–221 ■INDEX 905

scope and object lifetime, 221–223, 226 parameterOrder attribute, 686 serialization, 224–225 parameters, XSLT objects, serializing, 224–225. See also defining, 366–367 XML_Serializer package in style sheets, 393–395 oe parameter, 748 passing to templates, 368–369 Offer element, 655, 656 referencing, 367 omit-xml-declaration attribute, 382 scope of, in templates, 367–368 one-way operation, WSDL, 685–686 for user-defined functions, 379 oneOrMore pattern, 109–110 params element, 603 online bookmarks, 785–786 parent axis, XPath, 128 open() method, 315, 852 parent nodes, 125, 198–199 open source libraries. See PEAR parentNode property, 198–199, 857 open_basedir option, 175–176 parse() method, 513, 564 openMemory() method, 813–814, 872 parsed character data. See PCDATA content openUri() method, 813–814, 872 parsed entities, 55–57 operation element, 686, 689, 691, 693 parsed entity references, 450 Operation parameter, 664, 665, 670 parser attribute, 153 operator attribute, 755, 761 parser comparisons operators, XPath, 130 choosing parsers, 423–426 optimization document editing, 415–416

memory usage, 426–429 document navigation, 413–415 Find http://superindex.apress.com/ it faster at parser comparisons. See parser comparisons ease of use, 416–417 performance, 429–433 namespace support, 417–419 optional elements, 53–54 processing speed, 420–423 optional pattern, 106–107 streaming parsers, 410, 423–424 or operator, XPath, 132 system resource usage, 410, 411–413 orAllKeys option, 766 tree-based parsers, 409–410, 423–424 order parser modes, XML_Parser, 495 elements in element type declarations, 51–52 parser options, 173–174, 450–451 entity declarations, 55–56 parsers and parsing, 14 entity references, 58–59 Atom parser using XMLReader (example), node order 561–563 canonical XML, 450, 451–453 bypassing using CDATA sections, 26–27 XSLT, 360–362, 406–407 DOM extension, 165 schema elements, 74, 75 DOM parser using SAX (example), 306–310 order attribute, 362 epilogs and, 20 origin() function, 151 memory usage, 426–429 orLikeKeys option, 766 parsing DTDs, 512, 515 outbound() method, 790 parsing HTML documents, 504–506 output element, 686, 689, 693 performance, 429–433 outputBusiness() function, 770 pull parsers, 165, 312 outputMemory() method, 872 push parsers, 165, 270, 312 outputTemplate() function, 771 RSS 2.0 parser using SimpleXML (example), outputting XSLT result trees, 381–387 560–561 overviewDoc element, 762 SimpleXML extension, 164 ownerDocument property, 199, 857 using SAX. See parsing using SAX ownerElement property, 861 using XMLReader. See parsing using XMLReader ■P xml extension, 165, 270–272 packages, PEAR. See PEAR XML_DTD package, 512, 515 packets, WDDX XMLReader extension, 165 serializing data, 577–579, 579–581, 583–584, parsing speed 590–591 loading, unloading time, 429–430 unserializing data, 581–583, 584–585, 591–592 locating specific elements, 430–433 WDDX document structure, 570 optimizing, 429–433 Web service client (example), 587–589 parser comparisons, 410, 420–423 Web service server (example), 586–587 parsing using SAX XML_WDDX package, 589–592 byte index, 291–292, 304 PAD (Portable Application Description), 230–234, chunking data, 286–287, 304 262–268 column number, 291–292, 303–304 param element, 112, 603, 604 data from files, 287 parameter entities, 57–59, 69. See also general encoding conversions, 293–294 entities error handling, 292–293 906 ■INDEX

line number, 291–292 SOAP package, 734–735, 806 parser information, 291–292 UDDI package, 806–808 parsing into array structures, 288–291 Web services packages, 781 releasing parser, 294 XML_Beautifier package, 502–504 xml_parse() function, 285 XML_DTD package, 512–516 parsing using XMLReader XML_FastCreate package, 516–519 accessing attributes, 325–327, 331–332, 339 XML_HTMLSax package, 504–506 accessing node information, 320–323 XML_Parser package, 493–498 accessing nodes, 319–320, 330–331, 338–339 XML_RPC package, 622–628, 808 accessing sibling nodes, 323–325 XML_RSS package, 512, 563–566 namespaces and, 328–333 XML_Serializer package, 506–512 retrieving attribute values, 326 XML_Tree package, 498–501 validation using DTDs, 333 XML_Util package, 501–502 validation using RELAX NG, 334–335 XML_WDDX package, 589–592 parts attribute, 693 PEAR Package Manager, 492–493 passphrase option, 711 PECL, 812–813 password option, 711 per-mille attribute, 373 paths, XPath percent attribute, 373 abbreviated syntax, 131–132 performance. See also parser comparisons calculations in expressions, 146 large documents, processing, 426–427, 429–430 complex XPath expressions, 141–146 loading, unloading time, 429–430 equivalent XPointer expressions, 147 locating specific elements, 430–433 filtering node sets, 133–134 multiple documents, processing, 427–429 location paths, 127–132 persistence of SOAP classes, 728 namespaces and, 141–143 Person construct, 545 node tests, 128–130 personName element, 756 optimizing XPath expressions, 138–139 phone element, 756 predicates, 130 PHP 4, 163, 167, 300–306 value comparisons, 135–136, 144–145 PHP 5 XPath functions, 136–138, 144–145, 146 digital signature support, 448 XPath operators, 130 DOM extension. See DOM extension pattern element, 81 domxml/DOM extension migration, 228–230 pattern-separator attribute, 373 encryption support, 448 patterns, RELAX NG, 100–102. See also schemas, file security, 175–176 RELAX NG I/O handling, 175 attribute declarations, 101–102 libxml2-derived errors, 177–179 attribute pattern, 112, 113–114 PHP 4 migration, 300–306 choice pattern, 106, 114 protocols supported, 174–175 data pattern, 114 Safe Mode support, 175–176 element declarations, 101–103 SOA and, 9–10 empty pattern, 106 stream contexts, 176–177 external patterns, 119–121 streams, 174–177 group pattern, 106 WAP detection, 837–838 interleave pattern, 108–109 XML extensions, 163, 164–167 list pattern, 110–111 PHP functions mixed pattern, 106 in SOAP servers, 725–728 named patterns, 117–119 in style sheets, 396–399, 401, 402 oneOrMore pattern, 109–110 php.ini options, 175–176 optional pattern, 106–107 PI constant, 317, 318, 850 value pattern, 112–113, 113, 114 PI nodes zeroOrMore pattern, 109–110 canonical XML, 455–456 PCDATA content, 52–54 creating using XSLT, 353–354 PEAR XPath, 124, 127 installing, 492–493 piHandler() method, 494 purposes and guidelines, 491–492 PIs (processing instructions), 28, 88, 279 Services_Amazon package, 781–785 point node type, 149 Services_Delicious package, 785–786 port element, 695–696 Services_Ebay package, 786 port type element, 685 Services_Google package, 786–789 port types, WSDL, 685–690 Services_Technorati package, 789–793 Portable Application Description (PAD), 230–234, Services_Weather package, 793–797 262–268 Services_Webservice package, 797–802 position() function, 136 Services_Yahoo package, 802–806 positiveInteger type, 842 ■INDEX 907

POST, HTTP publicId property in REST architecture, 636, 637 DOMDocumentType class, 864 XML-RPC request headers, 601–602 DOMEntity class, 865 preceeding axis, XPath, 128 DOMNotation class, 865 preceeding-sibling axis, XPath, 128 published element, 550 predicates, XPath, 130 Publisher API, UDDI, 767–768, 773–780 calculations in expressions, 146 Publisher parameter, 664 complex XPath expressions, 141–146 publisherAssertion structure, 763–764 equivalent XPointer expressions, 147 publishing filtering node sets, 133–134 Web services. See UDDI (Universal Description, namespaces and, 141–143 Discovery, and Integration) optimizing XPath expressions, 138–139 XML applications, 6–7 value comparisons, 135–136, 144–145 pull parsers, 165, 312 XPath functions, 136–138, 144–145, 146 PurchaseURL element, 670, 672 XPath operators, 130 push parsers, 165, 270, 312 prefix property, 321, 330–331, 851, 858 PUT (HTTP), 636, 637 prefixes attribute uniqueness, 35–36 ■Q in exclusive XML canonicalization, 457–459 q parameter, 748 in RELAX NG schemas, 101 QName type, 841 in XMLReader, 330–331 QNames (qualified names). See also namespaces Find http://superindex.apress.com/ it faster at in XPath expressions, 142 namespaces and, 31, 32, 35 namespace prefixes, 31, 33, 34, 218–219, 227 XPath expressions, 128–130 qualified names, RELAX NG schemas, 117 qualified names, RELAX NG schemas, 116–117 reserved prefixes, 33 quantified expressions, 161 user-defined functions, EXSLT, 378–380 queries, XPath. See expressions, XPath WSDL prefix/namespace mappings, 674 query() method, 216, 217, 856 preserveWhiteSpace property, 859 query parameter, 648, 652 previousSibling property, 198, 857 Price element, 655 ■R PriceFrom element, 652 range() function, 150 PriceTo element, 652 range-inside() function, 150 primitive types, 73, 839–841 range node type, 149 priority attribute, 343–344 range-to() function, 149–150 procedural interface, XMLWriter, 819–820 RatingUrl element, 653 procedure calls, 595. See also XML-RPC rawurlencode() function, 665 processContents attribute, 84 RDF element, 524 processing instruction nodes RDF Site Summary, 522. See also RSS 1.0 (RDF Site canonical XML, 455–456 Summary) creating using XSLT, 353–354 read() method, 319–320, 333, 334, 852 processing instructions (PIs), 28 readInnerXml() method, 852, 878 annotation elements, 88 readOuterXml() method, 852, 878 SAX event handlers, 279 readString() method, 852, 878 processing speed Really Simple Syndication. See RSS 2.0 (Really optimizing, 429–433 Simple Syndication) parser comparisons, 410, 420–423 recordset element, 574–576 ProcessingInstruction interface, 187 recordset type, 569 Product Search service, Yahoo, 651–659 recover property, 859 ProductName element, 652, 655 ref attribute, 79, 93 prolog, 18–20 Reference element, 464, 466, 467 properties references domxml/DOM extension migration, 229 character references, 15–16 extending DOM classes, 220–221 digital signatures, 467–469, 472–473 system properties, 375–376 element group references, 79 proxy servers, 176–177 entity references, 28–29 proxy_host option, 711 for restricted characters, 17 proxy_login option, 711 registering DOM classes, 885–887 proxy_password option, 711 registerNamespace() method, 218–219, 856 pubDate element, 541 registerNodeClass() method, 861, 885–887 public identifiers, 46–47 registerPHPFunctions() method, 390, 396, 867 public keys, 465 registerXPathNamespace() method, 261, 853 PUBLIC keyword, 47 registries. See UDDI registries 908 ■INDEX

rel attribute, 546 client (example), 643–645 relative paths, XPath, 127 HTTP methods, 636–637 relative URIs, 42–43 server (example), 641–643 RELAX NG schemas. See schemas, RELAX NG URIs and, 638–639 relaxNGValidate() method, 216, 861 Web services, 11–12, 634 relaxNGValidateSource() method, 216, 861 XML representation of resources, 634–636 remote content, including. See XInclude Yahoo Product Search query (example), 653–659 remote document access, 176–177 Yahoo Web Search query (example), 648–651 Remote Method Invocation (RMI), 10 Yahoo Web services and, 12, 646 remote procedure calls, 595. See also XML-RPC restricted characters, 17 complex type document literal calls, 717–718 restriction element, 80 eBay Web services, 743–744 restricts option, 788 simple type RPC-encoded calls, 715–717 restricts parameter, 748 SoapClient class, 715–718 Result element, 647, 652 xmlrpc extension, 166 result trees, XSLT remote shopping cart. See shopping cart, Amazon attributes, 351–352 removeAttribute() method, 862 comment nodes, 354 removeAttributeNode() method, 862 copying nodes, 354–355 removeAttributeNS() method, 862 elements, 350–351 removeChild() method, 212–213, 858 formatted numbers, 362–366, 372–373 removeLineBreaks option, 503 HTML documents, generating, 356–357 removeParameter() method, 390, 393, 395, 867 named attribute sets, 352–353 removing nodes from trees, 212–213, 225 node sets, 358–360, 360–362, 406–407 repetitive processing, XSLT, 358 outputting, 381–387 replaceChild() method, 213, 858 processing instruction nodes, 353–354 replaceData() method, 863 retrieving current node, 374 replacing text in documents. See entities saving to URIs, 378 Representational State Transfer. See REST text nodes, 353, 356 (Representational State Transfer) results parameter, 648, 652 representations of resources. See REST ResultSet element, 646–647, 652 (Representational State Transfer) retrieving resources, 636–637. See also REST request-response operation, WSDL, 686–698 (Representational State Transfer) requests, XML-RPC. See also XML-RPC reusing content. See XInclude request format, 603–605 Rich Site Summary, 522. See also RSS 2.0 (Really request header, 601–602 Simple Syndication) XML-RPC client (example), 612–613, 614–616 rights element, 548, 550 XML-RPC server (example), 617–618, 619–620 RNG files, 101. See also schemas, RELAX NG XML_RPC_Message class, 624–625 root element #REQUIRED attribute default, 60 RELAX NG schemas, 101 #REQUIRED value, 36–38 scope of declarations, 89–91 reserved names, 16 XML documents, 18, 20 resetOptions() method, 503, 510 root node, 124, 125, 453 resolveExternals property, 859 round() function, 138 Resource Description Framework (RDF), 522 rowCount attribute, 574–575 resource identifiers, 633 RPC/encoded message format, WSDL, 682 resources, 633 RPC/literal message format, WSDL, 682–683 links between (XLink), 157–159 RSS 1.0 (RDF Site Summary) representations of. See REST (Representational channels, 524–526, 531, 532 State Transfer) content blocks, 527–528, 532–534 ResponseGroup parameter, 664 Content module, 532–534 responses, XML-RPC. See also XML-RPC document structure, 524 error handling, 607, 614, 618 Dublin Core module, 530–531 response format, 606–607 forms, 528–529 response header, 605 history of RSS, 521–522 XML-RPC client (example), 613, 614 images, 526–527 XML-RPC server (example), 618, 620 sample document, 523–524 XML_RPC_Response class, 626 selecting feed technologies, 550–551 REST (Representational State Transfer), 12, 14, 633 Syndication module, 531–532 adding integers (example), 639–640 using DOM (example), 551–557 Amazon item search query (example), 664–666 using XML_RSS (example), 563–566 Amazon remote shopping cart query (example), RSS 2.0 (Really Simple Syndication) 667–672 channels, 536–537 Amazon Web services and, 660–661 content blocks, 539–541 ■INDEX 909

document structure, 535–536 schemaLocation attribute, 93, 99 forms, 538–539 schemas, RELAX NG, 100–104. See also DTDs history of RSS, 521–522 (Document Type Definitions); schemas, images, 538 XML modules. See modules, RSS attributes, 113–114 parser, SimpleXML (example), 560–561 data types, 102, 114 sample document, 535 defines, 117–119 selecting feed technologies, 550–551 elements. See elements (RELAX NG) using DOM (example), 551–555, 556–557 external patterns, 119–121 using XML_RSS (example), 563–566 mixed element content, 107–108, 111–112 RSS1 class, 555–556 namespaces and, 101, 115–117 RSS2 class, 556–557 patterns. See patterns RSS documents, 391–392 root element, 101 rss element, 535 specifications and tutorial, 121 RSS technologies validation, 216 Atom. See Atom schemas, XML, 71. See also DTDs (Document Type history of, 521–522 Definitions); schemas, RELAX NG RSS 1.0. See RSS 1.0 (RDF Site Summary) annotation elements, 88 RSS 2.0. See RSS 2.0 (Really Simple Syndication) attributes. See attributes (XML schemas) Ruby, Sam, 522 complex element content, 86–87

complex types, 73–76, 84–85 Find http://superindex.apress.com/ it faster at ■S data types, 72–76 Safe Mode support, PHP 5, 175–176 DTDs vs., 71, 90 safe_mode_gid setting, PHP, 175–176 element name substitutions, 77–78 safeSearch option, 788 elements. See elements (XML schemas) safeSearch parameter, 748 empty elements, 85 SAP UDDI registry, 765, 767, 769–772, 773–780. See mixed element content, 85–86 also UDDI (Universal Description, multiple, combining, 91–93, 94–97 Discovery, and Integration) namespace declarations, 76 save() method, 191, 861 namespaced schemas, 94–100 save_binding() function, 768 schema element, 72 save_business() function, 768, 774 scope of declarations, 89–91, 93 saveDocumentToFile() method, 825 SDO Data Access Services, 821–823 saveHTML() method, 192, 861 simple types, 72–73, 83–84 saveHTMLFile() method, 192, 861 specifying namespaces, 72 save_publisherAssertions() function, 768 structure, 76 save_service() function, 768, 776 type definitions, 839 save_tModel() function, 768, 778 validation, 45–46, 215–216 saveXML() method, 191, 483, 861 schemaValidate() method, 215–216 SAX (Simple API for XML), 14, 165, 269–270 schemaValidateSource() method, 215–216, 861 DOM parser (example), 306–310 scheme attribute, 546 event handlers, 274–285, 297–300, 302–303, scope 305–306 extending DOM classes, 221–223, 226, 885–887 namespaces and, 294–297 global declarations, 95 parser, creating, 272 names in RELAX NG schemas, 117 parser options, 273–274 namespaces, 33–35 parsing documents parameters, 367–368 byte index, 291–292, 304 qualified local declarations, 95–97 chunking data, 286–287, 304 root element declaration, 95 column number, 291–292, 303–304 schema declarations, 89–91, 93 data from files, 287 unqualified local declarations, 94–95 encoding conversions, 293–294 variables, 367–368 error handling, 292–293 screen scraping, 12 line number, 291–292 SDO Data Access Service, 820–826 parser information, 291–292 SDO_XML_DAS, 825–826 parsing into array structures, 288–291 search() method, 788, 790 releasing parser, 294 search services, Google xml_parse() function, 285 doGetCachedPage() function, 746–747 target encoding, 300 doGoogleSearch() function, 746, 747–748 using xml extension, 270–272 doSpellingSuggestion() function, 746–747 scalar property, 611 GoogleSearchResult structure, 745, 748–750 scalarval() method, 623 registration and setup, 744 schema element, 72 Services_Google package, 788–789 910 ■INDEX

SearchIndex parameter, 664, 665 Services_Google package, 786–789 searching Services_Technorati class, 789–790 Amazon item searches, 663–666 Services_Technorati package, 789–793 using Google. See search services, Google serviceSubset option, 767 using Technorati, 789–793 Services_Weather package, 793–797 Yahoo Product Search service, 651–659 Services_Webservice class, 798 Yahoo Web Search service, 648–651 Services_Webservice package, 797–802 searchLocation() method, 794 Services_Yahoo package, 802–806 secret keys, HMAC hash, 444 Services_Yahoo_ContentAnalysis class, 805–806 security Services_Yahoo_Search class, 802–805 canonical XML. See canonical XML setAdultOK() method, 803 encryption. See encryption setAppID() method, 803, 806 file security support, PHP 5, 175–176 setAttribute() method, 208–209, 862 general considerations, 441–442 setAttributeNode() method, 208, 862 message integrity, 442–445 setAttributeNodeNS() method, 208, 862 PHP function calls, restricting, 396 setAttributeNS() method, 203, 208–209, 863 signatures. See digital signatures setClass() method, 728, 871 select attribute setContext() method, 806 xsl:apply-templates element, 346–347 _setCookie() method, 871 xsl:for-each element, 358 setFormat() method, 803 xsl:variable, xsl:param elements, 366 setIdAttribute() method, 227, 863, 883 self axis, XPath, 128 setIdAttributeNode() method, 863, 883 send() method, 625 setIdAttributeNS() method, 863, 883 Seq element, 525, 555 setIndent() method, 816, 872 sequence element, 74, 75, 78–79 setIndentString() method, 816 sequence lists, 51 setInput() method, 495 sequences, XPath 2.0, 159–160 setInputFile() method, 495 serialize() method setInputString() method, 495 PHP, 224 setLocale() method, 782 XML_RPC_Response class, 626 _setLocation() method, 714–715, 871 XML_Serialize class, 509 setOption(), setOptions() methods, 503, 509, 510 XML_WDDX package, 590 setParameter() method, 390, 393–394, 862 serialized data setParserProperty() method, 316–317, 852 canonical XML, 450–451 setPersistence() method, 728, 871 encrypting and decrypting, 446–448, 483 setQuery() method, 804, 806 hashing, 443–445 setRelaxNGSchema() method, 334, 335, 852 node order for canonical XML, 451–453 setRelaxNGSchemaSource() method, 334 serializing data setResultNumber() method, 804 arrays. See XML_Serializer package _setSoapHeaders() method, 718–719, 871 DOM objects, 224–225 setStart() method, 804 objects. See XML_Serializer package setType() method, 804 WDDX data SGML (Standardized Generalized Markup complex data, 579–581, 583–584, 590–591 Language), 2–3 simple data, 577–579, 583–584, 590–591 SHA1 hash, 443 unserializing data, 581–583, 584–585, shallow copies of nodes, 354–355 591–592 shared external subsets, 68–70 XML_WDDX package, 590–591 shopping cart, Amazon, 666–672, 784–785 Server fault code, SOAP, 702 short type, 842 servers show attribute, 158–159 REST Web service (example), 641–643 sibling nodes, DOM extension, 198 SOAP servers. See SOAP servers Signature element, 463 validating server-based data, 826–830 signature key, 626, 627 WDDX Web service server (example), 586–587 SignatureMethod element, 464, 470, 473 XML-RPC server (example), 617–622, 626–628 signatures. See digital signatures Service Data Objects (SDO), 820–826 SignatureValue element, 463, 466, 470 service element, 695–696 SignedInfo element, 463, 470, 473 Service parameter, 665 signer authentication, 460. See also digital serviceKey attribute, 758, 759 signatures services() method, 794 SIGNIFICANT_WHITESPACE constant, 318, 850 Services_Amazon package, 781–785 similar_ok parameter, 648 Services_AmazonECS4 class, 782 SimpleXML, 164, 239, 852–854, 879–883 Services_Delicious package, 785–786 attributes, 255–256, 256–257 Services_Ebay package, 786 child elements, 252–253 ■INDEX 911

choosing parsers, 424–425, 426 remote function calls, 715–718 document editing, 415, 416 service location, specifying, 714–715 document navigation, 414–415 services, inspecting, 712–714 DOM interoperability, 250, 253, 255, 434–436 SoapClient class. See SoapClient class ease of use, 410, 416–417 SOAP extension, 166, 867–871 element content, 243–244, 251–252 clients. See SOAP clients element names, 247–250 enabling, 706 element nodes, 242–243, 245–250 servers. See SOAP servers importing nodes from DOM extension, 434–435 SoapClient class, 710–723 large document processing, 410, 411, 412, 413 SoapFault class, 709–710, 729–730, 870 locating specific elements, 432, 433 SoapHeader class, 708 memory usage, 426–427 SoapParam class, 709 namespace support, 410, 419, 879–883 SoapServer class, 724–734 namespaces, registering, 261 SoapVar class, 706–708 optimizing, 426–427, 432, 433 SOAP faults, 701–704, 709–710, 729–730, 870 PAD template (example), 262–268 SOAP header entries, 699–701, 708, 718–719, performance, 432, 433 730–732 removing elements from tree, 253–255 SOAP package, 734–735, 806 replacing subtrees, 253 SOAP servers RSS 2.0 parser (example), 560–561 creating, 724–725

saving XML content, 241 eBay. See eBay Web services Find http://superindex.apress.com/ it faster at SimpleXMLElement class, 240–241, 257–258 handling client requests, 729 system resource usage, 410, 411, 412, 413 registering function handlers, 725–728 XPath support, 260–261 returning SOAP faults, 729–730 Yahoo Web Search query (example), 650–651 SOAP headers, 730–732 SimpleXML extension, 258–260, 879–883 WSDL and, 723–724, 732–734 simplexml mode, 506 soapAction attribute, 692 SimpleXMLElement class, 239–258, 257–258 SOAP_ACTOR_NEXT constant, 731 simplexml_import_dom() function, 434–435, 853 soap:address element, 695–696 simplexml_load_file() function, 239–241, 853 soap:binding element, 691 simplexml_load_string() function, 239–241, 853 _soapCall() method, 719–720, 744, 871 simplified inline style sheets, 343 SoapClient class, 870–871 site parameter, 648 _construct() method, 710–712 sleep() method, 224–225 _doRequest() method, 720–722, 870 SOA (Service Oriented Architecture), 10 _getFunctions() method, 712 SOAP, 11–12, 14, 867–871 _getLastRequest() method, 722 clients. See SOAP clients _getLastRequestHeaders() method, 722 eBay and. See eBay Web services _getLastResponse() method, 722 encoded variables, 706–708 _getLastResponseHeaders() method, 722 encoding style, 698 _getTypes() method, 712 Envelope element, 698–699 options, 711 error handling, 700, 701–704 remote function calls, 715–718 faults, 701–704, 709–710, 729–730, 870 _setLocation() method, 714–715 Google and. See Google Web services _setSoapHeaders() method, 718–719 header entries, 699–701, 708, 718–719 _soapCall() method, 719–720, 871 low-level function calls, 719–720 SoapFault class, 709–710, 729–730, 870 messages, 697, 701, 720–722 soap:fault element, 694 named parameters, 709 SOAP_FUNCTIONS_ALL constant, 727 PHP functions, 725–728 SoapHeader class, 869 request messages, 697, 704 soap:header element, 694 response messages, 697, 705 soap:headerfault element, 694 servers. See SOAP servers soap:operation element, 692 Services_Webservice package, 797–802 SoapParam class, 709, 869 UDDI APIs, 765–768 SOAP_PERSISTENCE_REQUEST option, 728 XML-RPC and, 10 SOAP_PERSISTENCE_SESSION option, 728 SOAP_... options constants, 867 SoapServer class, 724–725, 728, 729, 871 SOAP clients SoapVar class, 706–708, 868–869 creating, 710–712 soap_version option, 711 debugging client calls, 722–723 soap_version parameter, 724 eBay Web services implementation, 737–740 soap.wsdl_cache_dir option, 706 header entries, 718–719 soap.wsdl_cache_enabled option, 706 low-level function calls, 719–720 soap.wsdl_cache_ttl option, 706 messages, modifying, 720–722 solicit-response operation, WSDL, 698 912 ■INDEX

some quantifier, 161 parsing and processing speed, 410, 420, 423 Sort parameter, 664 SAX (Simple API for XML). See SAX (Simple API sort parameter, 652 for XML) sortByDateDesc option, 766 system resource usage, 410, 411, 413 sortByNameAsc option, 766 tree-based parsers vs., 410 sortByNameDesc option, 766 xml extension, 165, 270–272 sortCode attribute, 757 XMLReader extension, 165 sorting node sets streams, PHP 5, 174–177 canonical XML, 450, 451–453 strictErrorChecking property, 859 XSLT, 360–362, 406–407 string comparisons, XPath expressions, 135–136, source element, 541, 550 144–145 space attribute, 41–42 string element, 572, 598 space character, 16, 81–82 string() function, 137 space notation, 16 string-length() function, 137 special characters, 53, 450 string-range() function, 150 Specification element, 653 string type SpecificationLabel element, 653 RELAX NG, 103, 111–112 SpecificationList element, 653 WDDX, 569 SpecificationValue element, 653 XML schemas, 840 speed of parsing or processing, 410, 420–423, string values of XPath nodes, 124 429–433 struct element, 573–574, 577, 600 spell check, Google Web services, 787 struct type, 569 spelling suggestions, Yahoo Web services, 805–806 style attribute, 691, 692 spellingSuggestion() method, 787 style option, 711 splitText() method, 864 style sheets, 342 src attribute, 546 DOM extension (example), 399–400 stacking XPointer expressions, 147–148 importing to XSLT processor, 390–391 standalone attribute, 382 simplified inline style sheets, 343 standalone declaration, 19 templates. See templates, XSL standalone property, 859 variables and parameters, 366–369, 393–395 standardized data descriptions, 5–6 WAP Cascading Style Sheets (WCSS), 835 start element, 117–119, 120 XSL. See XSL (Extensible Stylesheet Language) start option, 788 XSLT. See XSLT (Extensible Stylesheet Language start parameter Transformations) GoogleSearchResult structure, 748 subclasses, DOM extension, 219–223 Yahoo Product Search request, 652 submit() method, 804, 806 Yahoo Web Search request, 648 subscription parameter, 648 start-point() function, 151 SUBST_ENTITIES constant, 850 start tags, 21, 23–24 substituteEntities property, 860 startAttribute() method, 872 substitutionGroup attribute, 77–78 startAttributeNs() method, 872 substitutions, element names, 77–78 startCdata() method, 872 substring-after() function, 137 startComment() method, 872 substring-before() function, 137 startDocument() method, 814, 872 substring() function, 137 startDtd() method, 873 substringData() method, 863 startDtdElement() method, 873 subtitle element, 548 startElement() method, 814, 872 subtrees startElementNs() method, 872 accessing, 197 startHandler() method, 494 bypassing in XMLReader, 323–325 startPi() method, 872 copying, 436–438 starts-with() function, 137 modifying, 252 steps, XPath, 127 replacing, 253 stock trader (XML-RPC example), 615–616, sum() function, 138 619–622 Summary element stream contexts, 176–177 Catalog element, Yahoo, 652 stream_context option, 711 Offer element, Yahoo, 655 streaming parsers Result element, Yahoo Web Search, 650 document editing capabilities, 410 summary element, 549 document navigation, 413, 415 super encryption, 476–477 document navigation capabilities, 410 syndication, 6 ease of use, 410 Atom. See Atom namespace support, 410 feeds using DOM, 551–560 parser comparisons, 410, 423–424 history of, 521–522 ■INDEX 913

parser, SimpleXML (example), 560–561 in XSLT, 353, 356 RSS 1.0. See RSS 1.0 (RDF Site Summary) whitespace in DOM tree, 182, 213 RSS 2.0. See RSS 2.0 (Really Simple Syndication) text output, XSLT result trees, 387 selecting technologies, 550–551 text pattern, 103, 111–112 Syndication module, 531–532 text value, Text construct, 544 Syndicator class, 552–555 textContent property, 858 system identifiers, 46–47 textInput element, 537, 538–539 SYSTEM keyword, 46–47 textinput element, 526, 528–529, 530 system-property() function, 375–376 Thumbnail element, 652, 655 system resource usage, parser comparisons, 410, time type, 840 411–413 timestamp property, 611 systemId property title attribute, 546 DOMDocumentType class, 864 Title element, 650 DOMEntity class, 865 title element DOMNotation class, 865 channel element, RSS 1.0, 525 system.listMethods() method, 608 channel element, RSS 2.0, 536 system.methodHelp() method, 608 entry element, Atom, 549 system.methodSignature() method, 608 feed element, Atom, 547 image element, RSS 1.0, 527 ■T image element, RSS 2.0, 538 tab character, 16, 23–24, 81–82, 455 item element, RSS 1.0, 528 Find http://superindex.apress.com/ it faster at tag key, array structures, 289 item element, RSS 2.0, 539 tagName property, 862 textinput element, RSS 1.0, 528 tags, 2, 3, 17–18, 21–22 textInput element, RSS 2.0, 538 target property, 866 tModel structure, 761–763, 778 targetNamespace attribute, 94–95, 99 tModelInstanceDetails element, 760, 763 Technorati Web service, 789–793 tModelKey attribute, 757, 761 templates, XSL, 343, 344–345 token type, 842 applying, 345–347 toKey element, 764 attribute value templates, 349–350 topTags() method, 790 built-in templates, 347–348 totalDigits element, 82 calling, 348–349 totalResultsAvailable attribute, 647 conflicts, resolving, 343–344 totalResultsReturned attribute, 647 elements, matching, 343 toXML() method, 519 elements, specifying for processing, 346–347 trace option, 711, 722 mode, specifying, 347 transformations, XSL names of templates, 343, 348–349 attribute value templates, 349–350 priority, specifying, 343–344 attributes, 351–352 variables and parameters, 366–369 CDATA sections and, 173–174 Yahoo Product Search query (example), 657 comment nodes, 354 templates (examples) copying nodes, 354–355 PAD template, 230–234, 262–268 current node, retrieving, 374 XSL template, 235–237 elements, 350–351 term attribute, 546 formatted numbers, 362–366, 372–373 term extraction, Yahoo Web services, 805–806 HTML documents, 356–357 terminate attribute, 376 named attribute sets, 352–353 test attribute, 360 node sets testing parsers. See parser comparisons processing, 358–360 text and text content. See also text nodes sorting, 360–362, 406–407 character data handlers, SAX, 276–277 processing instruction nodes, 353–354 in element type declarations, 53–54 RSS feed aggregation (example), 400–407 replacing. See entities style sheet, DOM extension (example), 399–400 simple types, 72–73, 83–84 templates. See templates, XSL text-only content, 53–54 text nodes, 353, 356 TEXT constant, 317, 318, 850 XSL extension, 166 Text construct, 544 XSLT processor. See XSLT processor text declarations, 47 Yahoo Product Search query (example), 657 Text interface, 187 transformToDoc() method, 390, 391, 392–393, 867 text() method, 872 transformToURI() method, 390, 391, 392, 867 text nodes. See also text and text content transformToXML() method, 390, 391–392, 867 in canonical XML, 455 translate() function, 137 in DOM extension, 209–211 transport attribute, 691 in XPath, 124, 126 914 ■INDEX

tree, DOM ■U attribute nodes, 207–209, 208–209 UDDI package, 806–808 attributes, 201–203 UDDI registries, 752 CDATA section nodes, 211 adding and updating information, 767–768, child nodes, 196–197 773–780 comments, 211 deleting information, 780 creating and instantiating documents, 188–189 querying, 765–767, 769–772, 807–808 document element, 193–194 SAP test registry, 765, 767, 768–780 document fragments, 211 UDDI (Universal Description, Discovery, and document node, 199, 203–204 Integration), 11–12, 751–752 element nodes, 204–206, 206–207 address structure, 756–757 elements, accessing by name, 199–201 bindings for services, 777–778 entity reference nodes, 211 bindingTemplate structure, 758–760 loading HTML data, 190–191 businessEntity structure, 754–757 loading XML data, 189–190, 193 businessService structure, 757–758 namespace declarations, 203 contact structure, 756 navigating between nodes, 196–201 data structures hierarchy, 753–754 node information, 194–196 deleting registry information, 780 parent nodes, 198–199 Inquiry API, 765–767 processing instruction nodes, 211 Publisher API, 767–768 removing nodes, 212–213, 225 publisherAssertion structure, 763–764 replacing nodes, 213 registries. See UDDI registries saving HTML data, 192 services, creating, 776–777 saving XML data, 191 specifications, 753 sibling nodes, 198 tModel structure, 761–763 subtrees, 197 usage of, 752 text nodes, 209–210 Unicode character set, 15 tree-based parsers union data types, 83 document editing capability, 410 union element, 84 document navigation, 410, 413, 415 Universal Business Registry (UBR), 751. See also DOM extension, 165 UDDI (Universal Description, Discovery, ease of use, 410 and Integration) namespace support, 410 Universal Description, Discovery, and Integration. parser comparisons, 409–410, 423–424 See UDDI (Universal Description, parsing and processing speed, 410, 420, 423 Discovery, and Integration) SimpleXML extension, 164 universally unique IDs (UUIDs), 753 streaming parsers vs., 409–410 UNKNOWN_TYPE constant, 868 system resource usage, 410, 411, 413 unloading time, 429–430 tree (document tree), 20, 182–183 unparsed entities troubleshooting declaration event handlers, 281–283 corrupted XML documents, 389 entity declarations, 57 default namespaces, element access, 227 notation declarations, 66–67 DTDs, adding manually, 227 referencing, 65–66 elements, retrieving by ID, 226 URIs, retrieving, 374–375 entity errors, 227 unparsed-entity-uri() function, 374–375 keys in style sheets, libxslt and, 389 unparsedHandler() method, 494 node access, extended classes and, 226 unqualified names, RELAX NG schemas, 115–116 nodes, removing from documents, 225 unserialize() method, 511 serializing DOM objects, 224–225 unserializing WDDX data, 581–583, 584–585, 590, true() function, 138 591–592 type attribute unset() method, 253–254, 257, 428 content element, Atom, 546 unsignedByte type, 842 link element, Atom, 546 unsignedInt type, 842 Text construct, 544 unsignedLong type, 842 XLink, 158 unsignedShort type, 842 XML schemas, 73, 74, 102 updated element, 547, 549 type definitions, 839 updating resources, 636, 637. See also REST type key, array structures, 289 (Representational State Transfer) type parameter, 648 uppercase characters, 17–18 type_name parameter, 707, 869 uri element, 545 type_namespace parameter, 707, 869 uri option, 711 types. See data types uri parameter, 724 types element, 678 ■INDEX 915

URIs (Uniform Resource Identifiers), 14 name/value pairs, 24 API versioning and, 638–639 node values, DOM extension, 195 base URIs, 42–43 var element, 573–574, 577 combining multiple schemas, 93 variable variables, 561 in REST architecture, 638–639 variables, XSLT, 366–368 namespaces, 31 verbosity option, 613 outputting to, XSLT, 392 version attribute, 342, 381, 383, 386 relative URIs, 42–43 version information XML Base specification, 42–43 API versioning, URIs and, 638–639 XPointer references, 146, 147 in XML declaration, 19 Url element libxml2 version, 172–173 Catalog element, Yahoo, 652 version option, 613 Offer element, Yahoo, 655 version property, 860 Result element, Yahoo Web Search, 650 VersionMismatch fault code, SOAP, 702 url element, 527, 538 URLs (Uniform Resource Locators), 14, 147 ■W use attribute wakeup() method, 224–225 attribute element, 79 WAP Cascading Style Sheets (WCSS), 835 WSDL, 693 WAP (Wireless Application Protocol), 830–838 xsl:key element, 371 W3C (World Wide Web Consortium), 14, 15 use-attribute-sets attribute, 351 W3C XML Schemas namespace, 72 Find http://superindex.apress.com/ it faster at use option, 711 WCSS (WAP Cascading Style Sheets), 835 user-derived types, 73, 80–83, 117–119 wddx extension, 166 UserLand Software, 522 WDDX (Web Distributed Data Exchange), 166, UserRating element, 652 567–568 use_soap_error_handler() function, 868 data types, 568–569, 571–576 useType attribute, 756, 757 enabling, 576 UTF-8, UTF-16 encodings, 15, 19, 169, 170–172 packets, 570 DOM extension and, 188, 226 serializing data, 577–581, 583–584, 590–591 SAX parser and, 293–294 unserializing data, 581–583, 584–585, 591–592 utf8_decode() function, 293, 849 Web service client (example), 587–589 utf8_encode() function, 293, 849 Web service server (example), 586–587 UUencode encoding, 67 XML_WDDX package, 589–592 UUIDs (universally unique IDs), 753 wddx_add_vars() function, 580 wddx_deserialize() method, 581–583 ■V wddxPacket element, 570 valid documents, 45 wddx_packet_end() function, 580, 581 VALIDATE constant, 850 wddx_packet_start() function, 580 validate() method, 214–215, 861 wddx_serialize_value() method, 577, 583 validateOnParse property, 860 wddx_serialize_vars() method, 577–578 validating server-based information, 826–830 weather information, Web service, 793–797 validation, 45–46 Weather.com, 793–797 DTDs. See DTDs (Document Type Definitions) Web Search service, Yahoo, 648–651 entity errors, 227 Web service definitions, WSDL, 695–696 libxml2-derived errors, 177 Web services, 10, 11–13 malformed document errors, 177 Amazon. See Amazon Web services RELAX NG schemas. See schemas, RELAX NG creating, 797–802 scope of declarations, 89–91, 93 del.icio.us Web service, 785–786 XInclude and, 152 discovering. See UDDI (Universal Description, XML schemas. See schemas, XML Discovery, and Integration) XML_DTD package, 512, 515 eBay. See eBay Web services XMLReader, 313 Google. See Google Web services value attribute, 80, 363 PEAR Web service packages, 781 value comparisons, XPath expressions, 135–136, publicly accessible (XMethods listing), 715 144–145 registries. See UDDI (Universal Description, value element, 533, 596, 599, 600, 603 Discovery, and Integration) value key, array structures, 289 REST. See REST (Representational State value() method, 626 Transfer) value pattern, 112–113, 113, 114 Technorati Web service, 789–793 value property, 321, 851, 861 UDDI. See UDDI (Universal Description, values Discovery, and Integration) attribute default values, 60–62 WDDX (example), 586–589 attribute values, 24, 25, 326, 450 weather information service, 793–797 916 ■INDEX

WSDL. See WSDL (Web Services Description XHTML (Extensible HTML), 24 Language) XHTML Mobile Profile (XHTML MP), 830, 833–836 Yahoo. See Yahoo Web services xhtml value, Text construct, 544 Web Services Architecture Working Group (W3C), xi prefix, 152 11 xi:fallback element, 155–157 Web Services Description Language. See WSDL xi:include element, 152–155 (Web Services Description Language) XInclude, 152 Web services extensions, 166 failed XIncludes, handling, 155–156 Web Services Interoperability Organization (WS-I), including external content, 152–155, 876–879 11, 673, 674, 699 optimizing memory usage, 426–427 well-formed documents, 45 XML Base specification, 42–43 whitespace xinclude() method, 861 formatting XML documents, 23–24 XLink, 42–43, 157–159 in canonical XML, 450, 455 xlink prefix, 158 in DOM tree, 182, 197, 213 XMethods, 715 in element type declarations, 50–52 XML Base specification, 42–43 in NMTOKEN, NMTOKENS types, 65 XML data in SAX parser, 273, 276–277, 290–291, 301 loading in DOM trees, 189–190 in user-derived types, 81–82 saving as HTML, 192 in XML documents, 16 saving as XML, 191 in XMLReader, 317, 318, 320 SDO access, 823–825 migrating to PHP 5, 301 XML declaration, 18–19, 450 xml:space attribute, 41–42 XML documents WHITESPACE constant, 317, 318, 850 adding DTDs manually, 227 whiteSpace element, 81–82 adding images to, 65–66 wholeText property, 864 body, 20 width element, 538 breaking into smaller documents, 426–427, wildcards, markup declarations, 49–50 436–438 Winer, Dave, 10, 522 CDATA sections, 26–27 Wireless Application Protocol (WAP), 830–838 characters in, 15–18 wml element, 832 cloning, libxslt library and, 389 WML (Wireless Markup Language), 830, 831–833 comments, 27–28 wrapper code, 229–230 as databases, 7–8 writeAttribute() method, 814, 872 document encryption, 476 writeCdata() method, 872 DOM extension. See DOM extension writeComment() method, 872 entity errors, 227 writeDtd() method, 873 external content. See XInclude writeElement() method, 814, 872 formatting, 23–24, 502–504 writeElementNs() method, 872 keys in style sheets, troubleshooting, 389 writePi() method, 872 large document processing, 426–427, 429–430 WS-I (Web Services Interoperability Organization), layout and components of, 18–20 11, 673, 674, 699 markup declarations. See markup declarations WSDL (Web Services Description Language), native XML databases, 8–9 11–12, 673–674 outputting, SimpleXML, 241 binding definitions, 690–695 parsing. See parsers and parsing data type definitions, 678–681 processing instructions, 28 document structure, 677–678 prolog, 18–20 example document, 675–677 root element, 18, 20 faults, 687, 693 signing. See digital signatures Google Web services and. See Google Web syntax, 21 services tree representation of (DOM), 182–183 message definitions, 681–685 using XMLWriter, 814–819 port type definitions, 685–690 validation. See validation prefix/namespace mappings, 674 XML-enabled databases. See native XML databases Services_Webservice package, 797–802 (NXDs) SOAP messages (examples), 697 XML encryption SOAP servers and, 723–724 character data encryption, 476 Web service definitions, 695–696 decrypting data, 484–489 detached encryption, 477 ■X document encryption, 476 XBRL (Extensible Business Reporting Language), 6 element encryption, 475 XHTML Basic, 833 encrypting data, 480–484 XHTML documents, 516–519 enveloping encryption, 477 ■INDEX 917

mixed content encryption, 475–476 XML_DTD_Parser class, 513–514 super encryption, 476–477 XML_DTD_Tree class, 513–514 XML encryption structure, 477–480 XML_DTD_XmlValidator class, 513, 515 XML encryption structure, 477–480 XML_ELEMENT_NODE constant, 854 XML (Extensible Markup Language), 1 xmlEncoding property, 860 history of, 2–4 XML_ENTITY_NODE constant, 854 HTML vs., 22–24 XML_ENTITY_REF_NODE constant, 854 uses for, 4–9 XML_ERROR... constants, 848 W3C design goals, 3–4 xml_error_string() function, 293, 849 xml extension, 165, 270–272, 847–849, 875–876. See XML_FastCreate class, 517 also SAX (Simple API for XML) XML_FastCreate package, 516–519 character data handlers, 301 xml_get_current_byte_index() function, 291–292, choosing parsers, 424, 426 303–304, 849 default handler, 302–303, 876 xml_get_current_column_number() function, document editing, 415 291–292, 303–304, 849 document navigation, 413–414, 415 xml_get_current_line_number() function, DOM parser, example code, 306–310 291–292, 849 ease of use, 410, 416 xml_get_error_code() function, 293, 849 large document processing, 410, 412, 413 XML_HTML_DOCUMENT_NODE constant, 854 namespace support, 410, 417–418, 419 XML_HTMLSax package, 504–506

system resource usage, 410, 412, 413 xmlLang property, 321, 851 Find http://superindex.apress.com/ it faster at target encoding, 300 XML_NOTATION_NODE constant, 854 XML_Parser package, 493–498 xmlns prefix, 31, 33. See also namespaces XMLReader compared to, 312–314 XML_OPTION_CASE_FOLDING option, 273, 505, XML extensions, PHP, 164–167. See also names of 847 specific extensions XML_OPTION_ENTITIES_PARSED option, 505 XML() method, 315, 852 XML_OPTION_ENTITIES_UNPARSED option, 505 XML output, XSLT result trees, 382–385 XML_OPTION_LINEFEED_BREAK option, 505 xml prefix, 16, 33 XML_OPTION_SKIP_TAGSTART option, 273, 274, XML representation of resources, 634–636. See also 290–291, 847 REST (Representational State Transfer) XML_OPTION_SKIP_WHITE option, 273, 274, XML-RPC, 595–596. See also xmlrpc extension 290–291, 847 data type elements, 596–600 XML_OPTION_TAB_BREAK option, 505 encoding and decoding data, 609–610 XML_OPTION_TARGET_ENCODING option, 273, error handling, 607, 614, 618 300, 847 faults, 607, 618 XML_OPTION_TRIM_DATA_NODES option, 505 relationship to SOAP, 10 xml_parse() function, 285, 849 requests, 601–602, 603–605, 612–613, 614–616, xml_parse_into_struct() function, 288, 849 617–618, 619–620 XML_Parser class, 494–497 responses, 605, 606–607, 613, 614, 618, 620 xml_parser_create() function, 272, 848 return values, 606–607 xml_parser_create_ns() function, 296, 848 server information, retrieving, 608 xml_parser_free() function, 294, 849 stock trader (example), 615–616, 619–622 xml_parser_get_option() function, 273, 849 XML-RPC client (example), 612–617, 625, 628 xml_parser_set_option() function, 273 XML-RPC server (example), 617–622, 626–628 XML_Parser_Simple class, 497–498 XML schemas. See schemas, XML XML_PI_NODE constant, 854 XML signatures, 460–461. See also encryption XMLReader, 311, 849–852, 876–879 creating, 466–471 Atom parser (example), 561–563 detached signatures, 462 choosing parsers, 424, 426 enveloped signatures, 461 copying subtrees, 436–438 enveloping signatures, 461–462 document editing, 415 references, 467–469, 472–473 document navigation, 413–414, 415 signatures, 470–471, 473–474 document processing example, 335–339 XML signature structure, 462–465 DOM interoperability, 436–438 XML_ATTRIBUTE_NODE constant, 854 ease of use, 410, 416, 417 XML_Beautifier package, 502–504 large document processing, 410, 413 XML_CDATA_SECTION_NODE constant, 854 locating specific elements, 430–431, 433 XML_COMMENT_NODE constant, 854 memory usage, 426–427 XML_DECLARATION constant, 318, 850 namespace support, 410, 418, 419 XML_DOCUMENT_FRAG_NODE constant, 854 namespaces and, 312–313, 328–333 XML_DOCUMENT_NODE constant, 854 node object properties, 320–321 XML_DOCUMENT_TYPE_NODE constant, 854 node type constants, 317–319, 850 XML_DTD package, 512–516 nodes, exporting to DOM objects, 328 918 ■INDEX

optimizing, 426–427, 430–431, 433 XML_Tree package, 498–501 parser properties, 316–317 XML_Tree_Node class, 499 parsing XML documents, 317–327, 338–339 XML_Unserializer class, 510–512 performance, 430–431, 433 XML_Util package, 501–502 processing speed, 313–314 xmlVersion property, 860 reading XML data, 315 XML_WDDX package, 589–592 system resource usage, 410, 413 XMLWriter extension, 811–820, 871–873 validation, 313 xmlwriter_open_memory() function, 819 xml extension compared to, 312–314 xmlwriter_open_uri() function, 819 XMLReader object, creating, 314–315 XPath, 14, 123. See also XPointer XSL interoperability, 438–439 axes, 127–128 XMLReader extension, 165, 876–879 calculations, 146 XMLReader object, 314–315 complex expressions, 141–146 XMLREADER_DEFAULTATTRS property, 316 data model, 124–127 XMLREADER_LOADDTD property, 316, 333 DOM extension support, 216–219 XMLREADER_SUBST_ENTITIES property, 316 equivalent XPointer expressions, 147 XMLREADER_VALIDATE property, 316, 333 filtering node sets, 133–134 xmlrpc extension, 166, 608. See also XML-RPC locating elements, 432–433 converting to XML-RPC data types, 610–611 location paths, 127–132 encoding and decoding data, 609–610 namespaces, registering, 218–219, 227, 261 stock trader (example), 615–616, 619–622 node sets, 127 XML-RPC client (example), 612–617, 625, 628 node tests, 128–130 XML-RPC server (example), 617–622, 626–628 nodes and node types, 124–127 XML_RPC package, 622–628 NXDs and, 8–9 XML_RPC_Client class, 625 optimizing expressions, 138–139 xmlrpc_decode() function, 609–610, 613 predicates, 130 xmlrpc_encode() function, 609–610 SimpleXML support, 260–261 xmlrpc_encode_request() function, 612–613, 618 value comparisons, 135–136, 144–145 xmlrpc_get_type() function, 610 XPath 2.0, 159–161 xmlrpc_is_fault() function, 614 XPath functions, 136–138, 144–145, 146 XML_RPC_Message class, 624–625 XPath operators, 130 XML_RPC_Response class, 626 XPointer extensions, 149–151 XML_RPC_Server class, 626–628 XPath 2.0, 159–161 xmlrpc_server_call_method() function, 620 XPath functions, 136–138 xmlrpc_server_create() function, 619 xpath() method, 260–261, 853 xmlrpc_server_destroy() function, 619 XPath operators, 130 xmlrpc_server_register_method() function, 619 XPointer. See also XPath xmlrpc_set_type() function, 610 character escaping, 146 xmlrpc_type property, 611 extending XPath functionality, 149–151 XML_RPC_Value class, 623–624 namespaces and, 148 XML_RSS package, 512 stacking XPointer expressions, 147–148 XML_Serializer class, 506–510 URI references, 146, 147 XML_Serializer package, 506–512 XPath expression equivalents, 147 xml_set_character_data_handler() function, 275, xpointer attribute, 153 848 XQuery, 159 xml_set_default_handler() function, 849 XSD_... SOAP constants, 868 xml_set_element_handler() method, 274, 275, 848 XSD files, 71 xml_set_end_namespace_decl_handler() function, xsd prefix, 72 849 XSL (Extensible Stylesheet Language), 341 xml_set_external_entity_ref_handler() method, templates. See XSL templates 280, 305–306, 849 transformations. See XSLT (Extensible xml_set_notation_decl_handler() method, Stylesheet Language Transformations) 281–282, 849 XMLReader interoperability, 438–439 xml_set_object() function, 297–300, 848 XSL extension. See XSL extension xml_set_processing_instruction_handler() XSL extension, 387–388, 866–867 method, 279, 849 constants, 388–389 xml_set_start_namespace_decl_handler() method, corrupted XML, troubleshooting, 389 297, 849 EXSLT modules and, 395–396 xml_set_unparsed_entity_decl_handler() method, output methods, 391–393 281–282, 849 parameters, 393–395 xmlStandalone property, 860 PHP functions, 396–399, 401 XML_TEXT_NODE constant, 854 RSS feed aggregation (example), 400–407 XML_Tree class, 499–501 style sheets. See style sheets ■INDEX 919

transforming data, 391–393 comment nodes, 354 XSLT processor. See XSLT processor conditional processing, 358–360 Yahoo Product Search service query (example), copying nodes, 354–355 656–659 current node, retrieving, 374 XSL functions, CDATA sections and, 173–174 debugging, 376 XSL templates, 343, 344–345 elements, 350–351 applying, 345–347 extension modules, 376–380 built-in templates, 347–348 external documents, 370 calling, 348–349 fallback capabilities, 380 elements, matching, 343 formatted numbers, 362–366, 372–373 elements, specifying for processing, 346–347 HTML document generation (example), mode, specifying, 347 356–357 names of templates, 343, 348–349 IDs, generating for node sets, 375 priority, specifying, 343–344 keys, 370–372, 389 resolving conflicts, 343–344 messages, 376 using DOM extension (example), 235–237 named attribute sets, 352–353 xsl:apply-templates element, 345–347, 359 outputting result trees, 381–387 xsl:attribute element, 351 processing instruction nodes, 353–354 xsl:attribute-set element, 352 processing node sets, 358 xsl:call-template element, 348–349 sorting node sets, 360–362, 406–407 xsl:choose element, 358, 359–360 style sheet, DOM extension (example), 399–400 Find http://superindex.apress.com/ it faster at xsl:comment element, 354 system property values, 375–376 xsl:copy element, 354–355 templates. See templates, XSL xsl:copy-of element, 355 text nodes, 353, 356 xsl:decimal-format element, 372–373 unparsed entity URIs, 374–375 xsl:element element, 350 user-defined functions, 378–380 xsl:fallback element, 380 XML Base specification, 42–43 xsl:for-each element, 358 XSLT processor. See XSLT processor xsl:if element, 358–359 XSLT processor xsl:key element, 370–372 corrupted XML, troubleshooting, 389 xsl:message element, 376 methods, 390 xsl:number element, 362–366 output methods, 391–393 xsl:otherwise element, 359–360 parameters, 393–395 xsl:output element, 381–382 PHP functions, 396–399, 401, 402 xsl:param element, 366–369, 379 RSS feed aggregation (example), 400–407 xsl:processing-instruction element, 353–354 style sheet, importing, 390–391 xsl:sort element, 358, 360–362, 406–407 transforming data, 391–393 xsl:stylesheet element, 342 XSLTProcessor class, 389–390, 866–867 xsl:template element, 343 xsl:text element, 353 ■Y xsl:transform element, 342 Yahoo Web services, 12, 646 xsl:value-of element, 356 error format, 660 xsl:variable element, 366–369 Flickr, 646 xsl:when element, 359–360 Product Search service, 651–659 xsl:with-param element, 368–369 registering, 649 XSL_CLONE_ALWAYS constant, 388–389, 866 results format, 646–647 XSL_CLONE_AUTO constant, 388–389, 866 Services_Yahoo package, 802–806 XSL_CLONE_NEVER constant, 388–389, 866 Web Search service, 647–651, 802–806 XSLT 2.0, 159 XSLT (Extensible Stylesheet Language ■Z Transformations), 14, 341 zero-digit attribute, 373 attribute value templates, 349–350 zeroOrMore pattern, 103, 109–110 attributes, 351–352