didou Sun Dec 19 17:16:44 2004 EDT
Modified files:
/phpdoc/en/reference/dom reference.xml
/phpdoc/en/reference/dom/functions dom-domdocument-validate.xml
dom-domxpath-query.xml
Log:
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 :) )
http://cvs.php.net/diff.php/phpdoc/en/reference/dom/reference.xml?r1=1.7&r2=1.8&ty=u
Index: phpdoc/en/reference/dom/reference.xml
diff -u phpdoc/en/reference/dom/reference.xml:1.7
phpdoc/en/reference/dom/reference.xml:1.8
--- phpdoc/en/reference/dom/reference.xml:1.7 Sun Dec 19 08:24:56 2004
+++ phpdoc/en/reference/dom/reference.xml Sun Dec 19 17:16:43 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.7 $ -->
+<!-- $Revision: 1.8 $ -->
<reference id="ref.dom">
<title>DOM Functions</title>
<titleabbrev>DOM</titleabbrev>
@@ -1097,44 +1097,58 @@
&reftitle.examples;
<para>
Many examples in this reference require an XML file. We will use the
- <filename>chapter.xml</filename> that contains the following:
+ <filename>book.xml</filename> that contains the following:
</para>
<para>
<example>
<title>chapter.xml</title>
<programlisting role="xml">
<![CDATA[
-<?xml version="1.0" standalone="yes"?>
-<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
-[ <!ENTITY sp "spanish">
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
]>
-<chapter language="en">
- <title language="en">Title</title>
- <para language="ge">
- &sp;
- <!-- comment -->
- <informaltable ID="findme" language="&sp;">
- <tgroup cols="3">
- <tbody>
- <row>
- <entry>a1</entry>
- <entry morerows="1">b1</entry>
- <entry>c1</entry>
- </row>
- <row>
- <entry>a2</entry>
- <entry>c2</entry>
- </row>
- <row>
- <entry>a3</entry>
- <entry>b3</entry>
- <entry>c3</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- </para>
-</chapter>
+<book id="listing">
+ <title>My lists</title>
+ <chapter id="books">
+ <title>My books</title>
+ <para>
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Title</entry>
+ <entry>Author</entry>
+ <entry>Language</entry>
+ <entry>ISBN</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>The Grapes of Wrath</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>0140186409</entry>
+ </row>
+ <row>
+ <entry>The Pearl</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>014017737X</entry>
+ </row>
+ <row>
+ <entry>Samarcande</entry>
+ <entry>Amine Maalouf</entry>
+ <entry>fr</entry>
+ <entry>2253051209</entry>
+ </row>
+ <!-- TODO: I have a lot of remaining books to add.. -->
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </chapter>
+</book>
]]>
</programlisting>
</example>
http://cvs.php.net/diff.php/phpdoc/en/reference/dom/functions/dom-domdocument-validate.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/reference/dom/functions/dom-domdocument-validate.xml
diff -u phpdoc/en/reference/dom/functions/dom-domdocument-validate.xml:1.4
phpdoc/en/reference/dom/functions/dom-domdocument-validate.xml:1.5
--- phpdoc/en/reference/dom/functions/dom-domdocument-validate.xml:1.4 Fri Dec
17 10:11:30 2004
+++ phpdoc/en/reference/dom/functions/dom-domdocument-validate.xml Sun Dec
19 17:16:44 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<refentry id="function.dom-domdocument-validate">
<refnamediv>
<refname>DOMDocument->validate</refname>
@@ -18,9 +18,40 @@
</methodsynopsis>
</classsynopsis>
<para>
- 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;.
</para>
<para>
+ You can also use the <literal>validateOnParse</literal> property of
+ <classname>DOMDocument</classname> to make a DTD validation.
+ </para>
+ <example>
+ <title>Example of DTD validation</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$dom = new DOMDocument;
+$dom->Load('book.xml');
+if ($dom->validate()) {
+ echo "This document is valid!\n";
+}
+?>
+]]>
+ </programlisting>
+ <para>
+ You can also validate your XML file while loading it:
+ </para>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$dom = new DOMDocument;
+$dom->validateOnParse = true;
+$dom->Load('book.xml');
+?>
+]]>
+ </programlisting>
+ </example>
+ <para>
See also <link
linkend="function.dom-domdocument-schemavalidate">DOMDocument->schemaValidate()</link>,
<link
linkend="function.dom-domdocument-schemavalidatesource">DOMDocument->schemaValidateSource()</link>,
<link
linkend="function.dom-domdocument-relaxngvalidate">DOMDocument->relaxNGValidate()</link>,
http://cvs.php.net/diff.php/phpdoc/en/reference/dom/functions/dom-domxpath-query.xml?r1=1.6&r2=1.7&ty=u
Index: phpdoc/en/reference/dom/functions/dom-domxpath-query.xml
diff -u phpdoc/en/reference/dom/functions/dom-domxpath-query.xml:1.6
phpdoc/en/reference/dom/functions/dom-domxpath-query.xml:1.7
--- phpdoc/en/reference/dom/functions/dom-domxpath-query.xml:1.6 Sun Dec
19 08:21:33 2004
+++ phpdoc/en/reference/dom/functions/dom-domxpath-query.xml Sun Dec 19
17:16:44 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.6 $ -->
+<!-- $Revision: 1.7 $ -->
<refentry id="function.dom-domxpath-query">
<refnamediv>
<refname>DOMXPath->query</refname>
@@ -25,23 +25,28 @@
</para>
<para>
<example>
- <title>Getting all entries begining with "b"</title>
+ <title>Getting all the english books</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
-$doc->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 @@
&example.outputs;
<screen>
<![CDATA[
-cell: b1
-cell: b3
+Found The Grapes of Wrath, by John Steinbeck
+Found The Pearl, by John Steinbeck
]]>
</screen>
</example>
@@ -68,19 +73,22 @@
<?php
$doc = new DOMDocument;
-$doc->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";
}
?>
]]>