Appendix F: PHPXML Classes


The PHPXML class is a collection of classes that process XML documents using PHP. PHPXML classes let you access XML documents using eXtensible Markup Language Path (XPath) language.

This appendix explains the packages of PHPXML classes. This appendix also explains the various classes present in the packages.

Classes in PHPXML

A package is a collection of classes that you can use to combine related classes. PHPXML consists of the following classes used for querying an XML document:

  • Xml_check

  • RDQL_query_document

  • RDF_iterator

  • RDQL_query

  • RDF_document_iterator

  • RDQL_db

  • RDQL_query_db

  • XqueryLite

  • class_xindice

PHPXML classes contain the following classes used for validating an XML document:

  • Path_parser

  • RDDL_parser

  • RSS_parser

  • RDF_parser

  • AbstractSAXParser

  • AbstractFilter

  • ExpatParser

  • FilterOutput

  • class_schematron

  • class_xslt

The XML_check Class

The Xml_check class validates whether an XML document is well-formed or not. If the XML document is well- formed , the Xml_check class returns various information, such as the number of elements, attributes, and text section. The Xml_check class also returns the line number and column number of the XML document where an error is encountered . The XML_check class contains various functions, such as:

  • get_xml_elements() : Provides the number of elements in an XML document.

  • get_xml_attributes() : Provides the number of attributes in an XML document.

  • get_xml_size() : Specifies the size of an XML document.

Resource Description Format Data Query Language

Resource Description Format (RDF) Data Query Language (RDQL) is a language that you use to query RDF documents from local file systems or URLs. RDQL is similar to Structured Query Language (SQL). You can implement RDQL using the following four classes:

  • RDQL_query_document

  • RDF_iterator

  • RDQL_query

  • RDF_document_iterator

The RDQL_query_document class implements the RDQL engine to query the RDF documents based on a URL and pathname. This class contains the rdql_query_url(string $query) function that queries the URL or string specified by the $query parameter. The rdql_query_url() function returns an associative array that contains the result of the RDQL query.

The RDQL engine uses the RDF_iterator class to query RDF documents from various sources, such as files and databases. The iterator is an object that specifies how to access and parse RDF documents. This class contains two functions, which are:

  • tuple_match(array $condition, array $row) : Returns the value, true, if a row satisfies a condition.

  • find_tuples(array $condition, array $row) : Returns the rows that satisfy a condition.

The RDQL_query class retrieves the RDQL rows from the RDF document using the RDQL engine. This class contains various functions, such as:

  • RDQL_query(RDF_iterator $iterator) : Accesses the RDF rows in the RDF documents. It is a constructor of the class that does not return any value.

  • parse_query(string $query) : Returns the results of the RDQL query.

  • tokenize(string $expression) : Returns an array that contains various sections, such as SELECT, FROM, and WHERE, of the RDQL expression.

  • parse_select(string $expression) : Returns an array that contains the SELECT section of the RDQL expression.

The RDF_document_iterator class contains an iterator that creates RDQL queries. This class does not contain any function.

Note  

RDF is a language that provides the accessed resources in the form of URLs.

The RDQL_db Class

The RDQL Database (DB) package is implemented using the class_rdql_db.php class. The RDQL DB package contains two classes, RDQL_db and RDQL_query_db. The RDQL_db class retrieves, stores, and deletes RDF documents from the MySQL database. Using the key of an RDF document, you can retrieve, store, and delete documents from the database. The primary key of a database is also called key. This class contains various functions, such as:

  • get_rdf_document(string $key) : Returns a PHP string that is accessed by the key of the RDF document.

  • store_rdf_document(string $url, string $key) : Returns the value, true, if the RDF document is stored in the database with the specified key. The $url variable provides a URL or file-path of the RDF document.

  • remove_rdf_document(string $key) : Deletes an RDF document from the database, based on the key of the document, which is specified as an argument of the function.

You can query multiple documents from the database using the RDQL_query_db class, by specifying the name of documents in the FROM section of the query. You can use asterisk, *, to query all the documents stored in the database. This class contains the rdql_query_db(string $query) function that returns the result of the RDQL query.

The Path_parser Class

The Path_parser class implements the event-driven parsers, such as Expat. This class invokes the handlers when an element is encountered in an XML document. This class contains various functions to parse the XML documents, such as:

  • init() : Parses the documents using a single object.

  • parse_file(string $url) : Returns the value, true, if the document indicated by the $url variable is successfully parsed.

  • set_handler(string $url, string $handler) : Processes XML elements when a specified handler is invoked.

The RDDL_parser Class

Resource Directory Description Language (RDDL) contains the RDDL_parser class that parses RDDL documents. This class contains a function that returns information pertaining to RDDL resources in an associative PHP array. Each element of an associative array contains various resources, such as role, href, type, title, and id. You can parse an RDDL document from URLs or files. The RDDL_parser class contains various functions, such as:

  • rddl_parse(string $url) : Returns the value, true, if the RDDL document indicated by the $url variable is successfully parsed.

  • get_resources(string $rddl) : Returns an associative array that contains resources found in an RDDL document.

  • get_error() : Returns an error message when the rddl_parser() function returns the value, false.

Note  

An eXtensible Hyper Text Markup Language (XHTML) document that contains the <resource> element is known as an RDDL document.

The RSS_parser Class

Really Simple Syndication (RSS) contains the RSS_parser class that implements the RSS1.0 parser. This class contains a function that parses RSS documents and returns an associative array. Each element of an associative array contains information about channels, such as channel data, channel_image, channel_textinput, and channel_items, in the RSS document. The RSS_parser class contains various functions, such as:

  • rss_parse(string $url) : Returns the value, true, if the RSS document specified by the $url variable is successfully parsed.

  • get_channel_data(string $url) : Returns an associative array that contains information about the channels, such as link, description, image, and text input.

  • get_items_data(string $url) : Returns an associative array that contains information about the items stored in the RSS document.

Note  

RSS is an XML-based language that displays information about Web sites, such as hyperlinks and the content of the Web sites.

The Rdf_parser Class

Resource Description Framework (RDF) contains the Rdf_parser class that parses the RDF document with the RDF specifications. The Rdf_parser class contains various functions, such as:

  • rdf_parser_create(string $encoding_scheme) : Returns the value, true, if a new parser is created. The $encoding_scheme parameter of the function, which specifies the encoding scheme to parse a document, is optional.

  • rdf_set_element_handler(string $start, string $end) : Invokes the handlers when the start and end elements of the non-RDF elements are encountered in the RDF document.

  • rdf_Parse(string $str, $length, $is_final) : Returns the value, true, if the RDF document is successfully parsed. The $str parameter indicates the chunk of data to be parsed, the $length parameter indicates the length of data to be parsed, and the $is_final parameter indicates the final data to be parsed.

Note  

RDF is a language that you can use to represent information on the Internet.

The XqueryLite Class

The XqueryLite class queries XML documents. This class lets you run queries in the Xquery 1.0 language, using files and PHP strings. The constructor of the XqueryLite class does not accept any parameter, and does not generate any result. The init() function initializes a query. The XqueryLite class contains various functions, such as:

  • evaluate_xqueryl(string $query) : Runs an Xquery Lite 1.0 query.

  • _get_root_name(object $node) : Returns the name of the root element of the XML document.

  • _parse_query(string $query) : Returns the result of the Xquery Lite expression.

Note  

XqueryLite is a language that queries XML documents.

The class_sax_filters.php Class

The Simple Application Programming Interface (API) for XML (SAX ) filters package contains the class_sax_filters.php class. This class contains a set of classes that implements the SAX parser filters. The Expat parser is an example of the SAX parser. Filters modify, query, update, and transform XML documents.

The class_sax_filters.php class contains four classes, which are:

  • AbstractSAXParser

  • AbstractFilter

  • ExpatParser

  • FilterOutput

The class_schematron Class

Schematron is a validation language that contains the class_schematron class to validate XML documents. You can validate XML documents using files, PHP strings and URLs. The class_schematron class contains various functions, such as:

  • compile_schematron_from_file(string $file) : Returns an XSLT stylesheet after compiling the Schematron script.

  • validate_mem_using_file(string $xml_str, string $validation_file) : Checks the string of the XML document specified in the $xml_str variable from the file specified in the $validation_file parameter.

  • validate_mem_using_mem(string $xml_str, string $validation_str) : Checks an XML document using the specified PHP string in the $validation_str parameter.

Note  

Schematron is a structured schema language that creates a tree structure for validating XML documents. You can use this class to perform validations in PHP.

The class_xslt Class

eXtensible Style sheet Language Transformation (XSLT) contains the class_xslt class to implement the XSLT processor. This class supports XSLT transformations and XML documents. This class contains functions that set the XSLT style sheet to be used from PHP strings and URLs. The class_xslt class contains various functions, such as:

  • getOutput() : Provides the output of the XSLT transformation.

  • transform(string $url) : Processes an XSLT transformation.

  • setXslString(string $xsl) : Assigns the string to be used for the XSLT stylesheet.

  • setXsl(string $url) : Assigns the URL to be used for the XSLT stylesheet.

The class_xindice Class

The class_xindice class accesses a Xindice 1.0 XML database using PHP script. The constructor of the class accepts two parameters, the URL of the Xindice server and the port of the server. A function of the class returns the number of documents present in the collection of databases. The class_xindice contains various functions, such as:

  • createCollection(string $base, string $collection) : Builds a collection of databases with the name specified in the $collection variable.

  • getDocumentCount(string $collectionLocation) : Provides the number of documents that exist in the specified location of a collection.

  • InsertDocument(string $collection, string $id, $xmldoc) : Sets a new document, specified by the $xmldoc variable, in the collection.

  • getDocument(string $collection, string $id) : Accesses a document from the database.

  • removeDocument(string $collection, string $id) : Deletes a document from a collection.

Note  

You need to install the Xindice XML-RPC plugin because the class_xindice class uses it.




Integrating PHP and XML 2004
Integrating PHP and XML 2004
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 51

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net