From fbd32bf69da246a1c90b12520a56fd0d20ae6091 Mon Sep 17 00:00:00 2001 From: Mehdi Achour Date: Sun, 19 Dec 2004 22:16:44 +0000 Subject: [PATCH] Use a valid docbook example file with a public DTD attached and update DOMXpath->query() example Also document DOMDocument->valid() and validateOnParse (as we have a valid dtd :) ) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@175096 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../functions/dom-domdocument-validate.xml | 35 ++++++++- .../dom/functions/dom-domxpath-query.xml | 30 ++++--- reference/dom/reference.xml | 78 +++++++++++-------- 3 files changed, 98 insertions(+), 45 deletions(-) diff --git a/reference/dom/functions/dom-domdocument-validate.xml b/reference/dom/functions/dom-domdocument-validate.xml index 6377f994fb..5604920d41 100644 --- a/reference/dom/functions/dom-domdocument-validate.xml +++ b/reference/dom/functions/dom-domdocument-validate.xml @@ -1,5 +1,5 @@ - + DOMDocument->validate @@ -18,8 +18,39 @@ - Validates the document based on its DTD. + Validates the document based on its DTD. &return.success; + If the document have no DTD attached, this method will return &false;. + + You can also use the validateOnParse property of + DOMDocument to make a DTD validation. + + + Example of DTD validation + +Load('book.xml'); +if ($dom->validate()) { + echo "This document is valid!\n"; +} +?> +]]> + + + You can also validate your XML file while loading it: + + +validateOnParse = true; +$dom->Load('book.xml'); +?> +]]> + + See also DOMDocument->schemaValidate(), DOMDocument->schemaValidateSource(), diff --git a/reference/dom/functions/dom-domxpath-query.xml b/reference/dom/functions/dom-domxpath-query.xml index 6afde732f1..a2af115e77 100644 --- a/reference/dom/functions/dom-domxpath-query.xml +++ b/reference/dom/functions/dom-domxpath-query.xml @@ -1,5 +1,5 @@ - + DOMXPath->query @@ -25,23 +25,28 @@ - Getting all entries begining with "b" + Getting all the english books Load('chapter.xml'); + +// We don't want to bother with white spaces +$doc->preserveWhiteSpace = false; + +$doc->Load('book.xml'); $xpath = new DOMXPath($doc); -// We starts from the root element -$query = '//chapter/para/informaltable/tgroup/tbody/row/entry[substring(., 1, 1) = "b"]'; +// We starts from the root element +$query = '//book/chapter/para/informaltable/tgroup/tbody/row/entry[. = "en"]'; $entries = $xpath->query($query); foreach ($entries as $entry) { - echo 'cell: ' . $entry->nodeValue . "\n"; + echo "Found {$entry->previousSibling->previousSibling->nodeValue}," . + " by {$entry->previousSibling->nodeValue}\n"; } ?> ]]> @@ -49,8 +54,8 @@ foreach ($entries as $entry) { &example.outputs; @@ -68,19 +73,22 @@ cell: b3 Load('chapter.xml'); +$doc->preserveWhiteSpace = false; + +$doc->Load('book.xml'); $xpath = new DOMXPath($doc); $tbody = $doc->getElementsByTagName('tbody')->item(0); // our query is relative to the tbody node -$query = 'row/entry[substring(., 1, 1) = "b"]'; +$query = 'row/entry[. = "en"]'; $entries = $xpath->query($query, $tbody); foreach ($entries as $entry) { - echo 'cell: ' . $entry->nodeValue . "\n"; + echo "Found {$entry->previousSibling->previousSibling->nodeValue}," . + " by {$entry->previousSibling->nodeValue}\n"; } ?> ]]> diff --git a/reference/dom/reference.xml b/reference/dom/reference.xml index 66921093fe..14632506bb 100644 --- a/reference/dom/reference.xml +++ b/reference/dom/reference.xml @@ -1,5 +1,5 @@ - + DOM Functions DOM @@ -1097,44 +1097,58 @@ &reftitle.examples; Many examples in this reference require an XML file. We will use the - chapter.xml that contains the following: + book.xml that contains the following: chapter.xml - + + - - Title - - &sp; - - - - - - a1 - b1 - c1 - - - a2 - c2 - - - a3 - b3 - c3 - - - - - - + + My lists + + My books + + + + + + Title + Author + Language + ISBN + + + + + The Grapes of Wrath + John Steinbeck + en + 0140186409 + + + The Pearl + John Steinbeck + en + 014017737X + + + Samarcande + Amine Maalouf + fr + 2253051209 + + + + + + + + ]]>