Skip to content

Commit c35be53

Browse files
committed
Document Dom\Attr methods
1 parent 5afc2f6 commit c35be53

File tree

5 files changed

+263
-6
lines changed

5 files changed

+263
-6
lines changed

reference/dom/dom/attr/isid.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<refentry xml:id="dom-attr.isid" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
3+
<refnamediv>
4+
<refname>Dom\Attr::isId</refname>
5+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('domattr.isid')/db:refnamediv/db:refpurpose)">
6+
<xi:fallback/>
7+
</xi:include>
8+
</refnamediv>
9+
10+
<refsect1 role="description">
11+
&reftitle.description;
12+
<methodsynopsis role="Dom\\Attr">
13+
<modifier>public</modifier> <type>bool</type><methodname>Dom\Attr::isId</methodname>
14+
<void/>
15+
</methodsynopsis>
16+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('domattr.isid')/db:refsect1[@role='description']/db:para[1])">
17+
<xi:fallback/>
18+
</xi:include>
19+
<simpara>
20+
According to the DOM standard this requires a DTD which defines the
21+
attribute ID to be of type ID. You need to validate your document by
22+
passing <constant>LIBXML_DTDVALID</constant> to the parse method.
23+
</simpara>
24+
</refsect1>
25+
26+
<refsect1 role="parameters">
27+
&reftitle.parameters;
28+
&no.function.parameters;
29+
</refsect1>
30+
31+
<refsect1 role="returnvalues">
32+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('domattr.isid')/db:refsect1[@role='returnvalues']/*)">
33+
<xi:fallback/>
34+
</xi:include>
35+
</refsect1>
36+
37+
<refsect1 role="examples">
38+
&reftitle.examples;
39+
<example>
40+
<title>Dom\Attr::isId() Example</title>
41+
<programlisting role="php">
42+
<![CDATA[
43+
<?php
44+
45+
// We need to validate our document before referring to the id
46+
$doc = Dom\XMLDocument::createFromFile('book.xml', LIBXML_DTDVALID);
47+
48+
// We retrieve the attribute named id of the chapter element
49+
$attr = $doc->getElementsByTagName('chapter')->item(0)->getAttributeNode('id');
50+
51+
var_dump($attr->isId()); // bool(true)
52+
53+
?>
54+
]]>
55+
</programlisting>
56+
</example>
57+
</refsect1>
58+
</refentry>
59+
<!-- Keep this comment at the end of the file
60+
Local variables:
61+
mode: sgml
62+
sgml-omittag:t
63+
sgml-shorttag:t
64+
sgml-minimize-attributes:nil
65+
sgml-always-quote-attributes:t
66+
sgml-indent-step:1
67+
sgml-indent-data:t
68+
indent-tabs-mode:nil
69+
sgml-parent-document:nil
70+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
71+
sgml-exposed-tags:nil
72+
sgml-local-catalogs:nil
73+
sgml-local-ecat-files:nil
74+
End:
75+
vim600: syn=xml fen fdm=syntax fdl=2 si
76+
vim: et tw=78 syn=sgml
77+
vi: ts=1 sw=1
78+
-->

reference/dom/dom/attr/rename.xml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<refentry xml:id="dom-attr.rename" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
3+
<refnamediv>
4+
<refname>Dom\Attr::rename</refname>
5+
<refpurpose>Changes the qualified name or namespace of an attribute</refpurpose>
6+
</refnamediv>
7+
8+
<refsect1 role="description">
9+
&reftitle.description;
10+
<methodsynopsis role="Dom\\Attr">
11+
<modifier>public</modifier> <type>void</type><methodname>Dom\Attr::rename</methodname>
12+
<methodparam><type class="union"><type>string</type><type>null</type></type><parameter>namespaceURI</parameter></methodparam>
13+
<methodparam><type>string</type><parameter>qualifiedName</parameter></methodparam>
14+
</methodsynopsis>
15+
<simpara>
16+
This method changes the qualified name or namespace of an attribute.
17+
</simpara>
18+
</refsect1>
19+
20+
<refsect1 role="parameters">
21+
&reftitle.parameters;
22+
<para>
23+
<variablelist>
24+
<varlistentry>
25+
<term><parameter>namespaceURI</parameter></term>
26+
<listitem>
27+
<simpara>
28+
The new namespace <acronym>URI</acronym> of the attribute.
29+
</simpara>
30+
</listitem>
31+
</varlistentry>
32+
<varlistentry>
33+
<term><parameter>qualifiedName</parameter></term>
34+
<listitem>
35+
<simpara>
36+
The new qualified name of the attribute.
37+
</simpara>
38+
</listitem>
39+
</varlistentry>
40+
</variablelist>
41+
</para>
42+
</refsect1>
43+
44+
<refsect1 role="returnvalues">
45+
&reftitle.returnvalues;
46+
<para>
47+
&return.void;
48+
</para>
49+
</refsect1>
50+
51+
<refsect1 role="errors">
52+
&reftitle.errors;
53+
<variablelist>
54+
<varlistentry>
55+
<term><classname>DOMException</classname> with code <constant>Dom\NAMESPACE_ERR</constant></term>
56+
<listitem>
57+
<simpara>
58+
Raised if there is an error with the namespace, as determined by
59+
<parameter>qualifiedName</parameter>.
60+
</simpara>
61+
</listitem>
62+
</varlistentry>
63+
<varlistentry>
64+
<term><classname>DOMException</classname> with code <constant>Dom\INVALID_MODIFICATION_ERR</constant></term>
65+
<listitem>
66+
<simpara>
67+
Raised if there already exists an attribute in the element with the same
68+
qualified name.
69+
</simpara>
70+
</listitem>
71+
</varlistentry>
72+
</variablelist>
73+
</refsect1>
74+
75+
<refsect1 role="examples">
76+
&reftitle.examples;
77+
<example xml:id="dom-attr.rename.example.basic">
78+
<title><methodname>Dom\Attr::rename</methodname> example to change both the namespace and qualified name</title>
79+
<simpara>
80+
This changes the qualified name of <literal>my-attr</literal> to
81+
<literal>my-new-attr</literal> and also changes its namespace to
82+
<literal>urn:my-ns</literal>.
83+
</simpara>
84+
<programlisting role="php">
85+
<![CDATA[
86+
<?php
87+
88+
$doc = Dom\XMLDocument::createFromString('<root my-attr="value"/>');
89+
90+
$root = $doc->documentElement;
91+
$attribute = $root->attributes['my-attr'];
92+
$attribute->rename('urn:my-ns', 'my-new-attr');
93+
94+
echo $doc->saveXml();
95+
96+
?>
97+
]]>
98+
</programlisting>
99+
&example.outputs;
100+
<screen>
101+
<![CDATA[
102+
<?xml version="1.0" encoding="UTF-8"?>
103+
<root xmlns:ns1="urn:my-ns" ns1:my-new-attr="value"/>
104+
]]>
105+
</screen>
106+
</example>
107+
<example xml:id="dom-attr.rename.example.only-name">
108+
<title><methodname>Dom\Attr::rename</methodname> example to change only the qualified name</title>
109+
<simpara>
110+
This only changes the qualified name of <literal>my-attr</literal>
111+
and keeps the namespace <acronym>URI</acronym> the same.
112+
</simpara>
113+
<programlisting role="php">
114+
<![CDATA[
115+
<?php
116+
117+
$doc = Dom\XMLDocument::createFromString('<root my-attr="value"/>');
118+
119+
$root = $doc->documentElement;
120+
$attribute = $root->attributes['my-attr'];
121+
$attribute->rename($attribute->namespaceURI, 'my-new-attr');
122+
123+
echo $doc->saveXml();
124+
125+
?>
126+
]]>
127+
</programlisting>
128+
&example.outputs;
129+
<screen>
130+
<![CDATA[
131+
<?xml version="1.0" encoding="UTF-8"?>
132+
<root my-new-attr="value"/>
133+
]]>
134+
</screen>
135+
</example>
136+
</refsect1>
137+
138+
<refsect1 role="notes">
139+
&reftitle.notes;
140+
<note>
141+
<simpara>
142+
It is sometimes necessary to change
143+
the qualified name and namespace <acronym>URI</acronym> together in one
144+
step to not break any namespace rules.
145+
</simpara>
146+
</note>
147+
</refsect1>
148+
149+
<refsect1 role="seealso">
150+
&reftitle.seealso;
151+
<simplelist>
152+
<member><methodname>Dom\Element::rename</methodname></member>
153+
</simplelist>
154+
</refsect1>
155+
156+
</refentry>
157+
<!-- Keep this comment at the end of the file
158+
Local variables:
159+
mode: sgml
160+
sgml-omittag:t
161+
sgml-shorttag:t
162+
sgml-minimize-attributes:nil
163+
sgml-always-quote-attributes:t
164+
sgml-indent-step:1
165+
sgml-indent-data:t
166+
indent-tabs-mode:nil
167+
sgml-parent-document:nil
168+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
169+
sgml-exposed-tags:nil
170+
sgml-local-catalogs:nil
171+
sgml-local-ecat-files:nil
172+
End:
173+
vim600: syn=xml fen fdm=syntax fdl=2 si
174+
vim: et tw=78 syn=sgml
175+
vi: ts=1 sw=1
176+
-->

reference/dom/dom/dom-attr.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@
158158

159159
</partintro>
160160

161-
<!-- &reference.dom.dom.entities.attr; -->
161+
&reference.dom.dom.entities.attr;
162162

163163
</reference>

reference/dom/domattr/isid.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
<refsect1 role="returnvalues">
3333
&reftitle.returnvalues;
34-
<para>
35-
&return.success;
36-
</para>
34+
<simpara>
35+
Returns &true; if this attribute is a defined ID, &false; otherwise.
36+
</simpara>
3737
</refsect1>
3838
<refsect1 role="examples">
3939
&reftitle.examples;
@@ -44,11 +44,11 @@
4444
<![CDATA[
4545
<?php
4646
47-
$doc = new DomDocument;
47+
$doc = new DOMDocument;
4848
4949
// We need to validate our document before referring to the id
5050
$doc->validateOnParse = true;
51-
$doc->Load('book.xml');
51+
$doc->load('book.xml');
5252
5353
// We retrieve the attribute named id of the chapter element
5454
$attr = $doc->getElementsByTagName('chapter')->item(0)->getAttributeNode('id');

reference/dom/versions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@
229229
<function name="dom\tokenlist" from="PHP 8 &gt;= 8.4.0"/>
230230
<function name="dom\xmldocument" from="PHP 8 &gt;= 8.4.0"/>
231231
<function name="dom\xpath" from="PHP 8 &gt;= 8.4.0"/>
232+
233+
<function name="dom\attr::isid" from="PHP 8 &gt;= 8.4.0"/>
234+
<function name="dom\attr::rename" from="PHP 8 &gt;= 8.4.0"/>
232235
</versions>
233236
<!-- Keep this comment at the end of the file
234237
Local variables:

0 commit comments

Comments
 (0)