document DOMAttr->isId() and DOMDocument->getElementById()

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@175105 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Mehdi Achour 2004-12-20 03:10:23 +00:00
parent 4e82a2f7d2
commit 75bff3178a
2 changed files with 64 additions and 5 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<refentry id='function.dom-domattr-isId'>
<refnamediv>
<refname>DOMAttr->isId</refname>
@ -18,8 +18,35 @@
</methodsynopsis>
</classsynopsis>
<para>
This function checks if the attribute is a defined ID.
This function checks if the attribute is a defined ID. &return.success;
</para>
<para>
According to the DOM standard this requires a DTD which defines the
attribute ID to be of type ID. You need to validate your document with
<link linkend="function.dom-domdocument-validate">DOMDocument->validate()</link>
or <literal>DOMDocument::validateOnParse</literal> before using this function.
</para>
<example>
<title>DOMDocument->getElementById() Example</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DomDocument;
// We need to validate our document before refering to the id
$doc->validateOnParse = true;
$doc->Load('book.xml');
// We retrieve the attribute named id of the chapter element
$attr = $doc->getElementsByTagName('chapter')->item(0)->getAttributeNode('id');
var_dump($attr->isId()); // bool(true)
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<refentry id="function.dom-domdocument-getelementbyid">
<refnamediv>
<refname>DOMDocument->getElementById</refname>
@ -18,8 +18,40 @@
<para>
This function is similar to
<link linkend="function.dom-domdocument-getelementsbytagname">DOMDocument->getElementsByTagName()</link>
but searches for an element with a given id. According to the DOM standard
this requires a DTD which defines the attribute ID to be of type ID.
but searches for an element with a given id.
</para>
<para>
According to the DOM standard this requires a DTD which defines the
attribute ID to be of type ID. You need to validate your document with
<link linkend="function.dom-domdocument-validate">DOMDocument->validate()</link>
or <literal>DOMDocument::validateOnParse</literal> before using this function.
</para>
<example>
<title>DOMDocument->getElementById() Example</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DomDocument;
// We need to validate our document before refering to the id
$doc->validateOnParse = true;
$doc->Load('book.xml');
echo "The element whose id is books is: " . $doc->getElementById('books')->tagName . "\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
The element whose id is books is: chapter
]]>
</screen>
</example>
<para>
See also <link linkend="function.dom-domdocument-getelementsbytagname">DOMDocument->getElementsByTagName()</link>.
</para>
</refsect1>
</refentry>