216 CHAPTER 6 DOCUMENT OBJECT MODEL (DOM) This example loads a scaled-down XML Schema from Chapter 3 into the string $schema. The method schemaValidateSource() is called on the DOMDocument object, $dom, to be validated. In this case, the document validates and returns the Boolean, TRUE, identified by the $isvalid variable. Validating with RELAX NG Validation using RELAX NG works in the same manner as validating with an XML Schema. It offers the same advantage in that the schema is associated at the time of validation, and document serialization is not required. Other than using RELAX NG for the schema and a minor difference in method names, the parameters, return values, and error issuance is the same as when using XML Schemas. The methods used with RELAX NG validation are relaxNGValidate() and relaxNGValidateSource(). The first method takes a URI, and the latter takes a string containing the XML for the RELAX NG schema. For example: $schema = ‘ ‘; $isvalid = $dom->relaxNGValidateSource($schema); var_dump($isvalid); Using the DOMDocument object, $dom, from the XML Schema example, the RELAX NG schema (in serialized form and set to the $schema variable) is validated against the document using the relaxNGValidateSource() method. Just like the other validation methods, this document successfully validates and returns the Boolean TRUEto the $isvalid variable. Using XPath The DOMXPath class in the DOM extension offers access to the underlying tree using XPath expressions, as examined in Chapter 4. This class is simple to use because it has minimal methods yet allows for complex expression. When running under PHP 5.0, a DOMNodeList containing nodes is the only return type available using the query() method. For PHP 5.1 and higher, the evaluate() method allows for a greater number of return types. Instantiating DOMXPath No factory methods exist for creating a DOMXPath object. DOMXPath is not part of the core DOM specification and exists solely to provide XPath support with the DOM extension. You can create a DOMXPath object using the newkeyword, passing the DOMDocument object to be used with
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services
No comments yet.
Sorry, the comment form is closed at this time.