Skip to content

Commit a8cf85b

Browse files
committed
[reference/simplexml] sync with en.
1 parent 3454eb2 commit a8cf85b

File tree

10 files changed

+138
-45
lines changed

10 files changed

+138
-45
lines changed

reference/simplexml/book.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 46a9cdd2dbef4ec89bf65fad9930e2feb78bbb98 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: c1f37a6c270aadbbb3da56a3973ffd62197adf2b Maintainer: takagi Status: ready -->
44
<!-- CREDITS: shimooka,hirokawa -->
55

6-
<book xml:id="book.simplexml" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
6+
<book xml:id="book.simplexml" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="interactive">
77
<?phpdoc extension-membership="bundledexternal" ?>
88
<title>SimpleXML</title>
99

reference/simplexml/examples.xml

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: a0ae28d3bc85f927c22649ebd9a590b921534b7d Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: 8ac065774e87c73919ee3508fc957adebe1c4408 Maintainer: takagi Status: ready -->
44
<!-- CREDITS: shimooka,hirokawa -->
55

66
<chapter xml:id="simplexml.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
77
&reftitle.examples;
88
<section xml:id="simplexml.examples-basic">
99
<title>基本的な SimpleXML の使用法</title>
10+
1011
<para>
1112
このリファレンスの多くの例では XML 文字列が必要です。それぞれの例で
1213
この文字列をくり返す代わりに、あるファイルにこの文字列を保存して、
@@ -18,7 +19,8 @@
1819
</para>
1920
<para>
2021
<example>
21-
<title>XML 文字列を設定するインクルードファイル example.php</title>
22+
<title>Include file examples/simplexml-data.php with XML string</title>
23+
<title>XML 文字列を設定するインクルードファイル examples/simplexml-data.php</title>
2224
<programlisting role="php" xml:id="simplexml.examples.movie">
2325
<![CDATA[
2426
<?php
@@ -59,11 +61,11 @@ XML;
5961
SimpleXML の容易さが最も明確に現われるのは、
6062
簡単な XML ドキュメントから文字列または数字を展開する時です。
6163
<example>
62-
<title><literal>&lt;plot&gt;</literal> を取得する</title>
64+
<title>Getting <literal>&lt;plot&gt;</literal></title>
6365
<programlisting role="php">
6466
<![CDATA[
6567
<?php
66-
include 'example.php';
68+
include 'examples/simplexml-data.php';
6769
6870
$movies = new SimpleXMLElement($xmlstr);
6971
@@ -92,7 +94,7 @@ echo $movies->movie[0]->plot;
9294
<programlisting role="php">
9395
<![CDATA[
9496
<?php
95-
include 'example.php';
97+
include 'examples/simplexml-data.php';
9698
9799
$movies = new SimpleXMLElement($xmlstr);
98100
@@ -118,7 +120,7 @@ PHP solves all my web problems
118120
<programlisting role="php">
119121
<![CDATA[
120122
<?php
121-
include 'example.php';
123+
include 'examples/simplexml-data.php';
122124
123125
$movies = new SimpleXMLElement($xmlstr);
124126
@@ -158,14 +160,14 @@ Mr. Coder played by El ActÓr
158160
<programlisting role="php">
159161
<![CDATA[
160162
<?php
161-
include 'example.php';
163+
include 'examples/simplexml-data.php';
162164
163165
$movies = new SimpleXMLElement($xmlstr);
164166
165167
/* 最初の映画の <rating> ノードにアクセスします。
166168
* また、その評価も出力します。*/
167169
foreach ($movies->movie[0]->rating as $rating) {
168-
switch((string) $rating['type']) { // 要素のインデックスとして、属性を取得します
170+
switch((string) $rating['type']) { // Get attributes as element indices
169171
case 'thumbs':
170172
echo $rating, ' thumbs up';
171173
break;
@@ -196,7 +198,7 @@ foreach ($movies->movie[0]->rating as $rating) {
196198
<programlisting role="php">
197199
<![CDATA[
198200
<?php
199-
include 'example.php';
201+
include 'examples/simplexml-data.php';
200202
201203
$movies = new SimpleXMLElement($xmlstr);
202204
@@ -226,7 +228,7 @@ My favorite movie.PHP: Behind the Parser
226228
<programlisting role="php">
227229
<![CDATA[
228230
<?php
229-
include 'example.php';
231+
include 'examples/simplexml-data.php';
230232
231233
$movies1 = new SimpleXMLElement($xmlstr);
232234
$movies2 = new SimpleXMLElement($xmlstr);
@@ -250,10 +252,14 @@ bool(false)
250252
<literal>&lt;character&gt;</literal> 要素をすべて見つけるには、
251253
以下のようにします。
252254
</simpara>
255+
<simpara>
256+
'<literal>//</literal>' は、ワイルドカードとして機能します。
257+
完全なパスを指定するには、スラッシュをひとつ省略します:
258+
</simpara>
253259
<programlisting role="php">
254260
<![CDATA[
255261
<?php
256-
include 'example.php';
262+
include 'examples/simplexml-data.php';
257263
258264
$movies = new SimpleXMLElement($xmlstr);
259265
@@ -263,10 +269,6 @@ foreach ($movies->xpath('//character') as $character) {
263269
?>
264270
]]>
265271
</programlisting>
266-
<simpara>
267-
'<literal>//</literal>' はワイルドカードとして動作します。絶対パスを指定するには、
268-
スラッシュを一つだけにします。
269-
</simpara>
270272
&example.outputs;
271273
<screen>
272274
<![CDATA[
@@ -286,7 +288,7 @@ Mr. Coder played by El ActÓr
286288
<programlisting role="php">
287289
<![CDATA[
288290
<?php
289-
include 'example.php';
291+
include 'examples/simplexml-data.php';
290292
$movies = new SimpleXMLElement($xmlstr);
291293
292294
$movies->movie[0]->characters->character[0]->name = 'Miss Coder';
@@ -337,7 +339,7 @@ echo $movies->asXML();
337339
<programlisting role="php">
338340
<![CDATA[
339341
<?php
340-
include 'example.php';
342+
include 'examples/simplexml-data.php';
341343
$movies = new SimpleXMLElement($xmlstr);
342344
343345
$character = $movies->movie[0]->characters->addChild('character');
@@ -415,6 +417,51 @@ blah
415417
</screen>
416418
</example>
417419
</para>
420+
<para>
421+
<example>
422+
<title>名前空間を扱う</title>
423+
<programlisting role="php">
424+
<![CDATA[
425+
<?php
426+
$data = <<<XML
427+
<movies xmlns="http://default" xmlns:a="http://a">
428+
<movie xml:id="movie1" a:link="IMDB">
429+
<a:actor>Onlivia Actora</a:actor>
430+
</movie>
431+
</movies>
432+
XML;
433+
434+
$movies = simplexml_load_string($data);
435+
436+
// 名前空間 http://www.w3.org/XML/1998/namespace は、"xml" として利用できます
437+
echo $movies->movie->attributes("xml", true)["id"] . "\n";
438+
439+
// 名前空間付きの属性は attributes() でアクセスできます。
440+
echo $movies->movie->attributes("a", true)["link"] . "\n";
441+
442+
// Using namespace URI allows document to use any namespace alias.
443+
444+
// 名前空間URI を使うと、ドキュメントを任意の名前空間のエイリアスとして使えます
445+
echo $movies->movie->attributes("http://a")["link"] . "\n";
446+
447+
// 子要素は children() を使ってアクセスできます
448+
echo $movies->movie->children("http://a")->actor . "\n";
449+
450+
// 名前空間付きで xpath() を使うには、名前空間をまず登録する必要があります
451+
$movies->registerXPathNamespace("a", "http://a");
452+
echo count($movies->xpath("//a:actor")) . "\n";
453+
454+
// デフォルトの名前空間であっても、登録が必要です
455+
$movies->registerXPathNamespace("default", "http://default");
456+
echo count($movies->xpath("//default:movie")) . "\n";
457+
458+
// この結果は空になります
459+
echo count($movies->xpath("//movie")) . "\n";
460+
?>
461+
]]>
462+
</programlisting>
463+
</example>
464+
</para>
418465
</section>
419466

420467
<section xml:id="simplexml.examples-errors">
@@ -495,4 +542,3 @@ vim600: syn=xml fen fdm=syntax fdl=2 si
495542
vim: et tw=78 syn=sgml
496543
vi: ts=1 sw=1
497544
-->
498-

reference/simplexml/functions/simplexml-import-dom.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 62514381ff35348ffc4061b691132e36adf96210 Maintainer: hirokawa Status: ready -->
3+
<!-- EN-Revision: 739803892eb2a24535d5269752097c3792542adb Maintainer: hirokawa Status: ready -->
44
<!-- CREDITS: shimooka -->
55
<refentry xml:id="function.simplexml-import-dom" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -75,6 +75,12 @@
7575
</row>
7676
</thead>
7777
<tbody>
78+
<row>
79+
<entry>8.4.0</entry>
80+
<entry>
81+
<classname>Dom\Document</classname> のサポートが追加されました。
82+
</entry>
83+
</row>
7884
<row>
7985
<entry>8.4.0</entry>
8086
<entry>
@@ -92,7 +98,7 @@
9298
&reftitle.examples;
9399
<para>
94100
<example>
95-
<title>DOM のインポート</title>
101+
<title><classname>DOMDocument</classname> のインポート</title>
96102
<programlisting role="php">
97103
<![CDATA[
98104
<?php
@@ -105,6 +111,26 @@ if (!$dom) {
105111
106112
$s = simplexml_import_dom($dom);
107113
114+
echo $s->book[0]->title;
115+
?>
116+
]]>
117+
</programlisting>
118+
&example.outputs;
119+
<screen>
120+
<![CDATA[
121+
blah
122+
]]>
123+
</screen>
124+
</example>
125+
<example>
126+
<title><classname>Dom\Document</classname> のインポート</title>
127+
<programlisting role="php">
128+
<![CDATA[
129+
<?php
130+
$dom = Dom\XMLDocument::createFromString('<books><book><title>blah</title></book></books>');
131+
132+
$s = simplexml_import_dom($dom);
133+
108134
echo $s->book[0]->title;
109135
?>
110136
]]>

reference/simplexml/functions/simplexml-load-file.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: d2939d46110158f98ace5c20761c808b04c905d8 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: c1f37a6c270aadbbb3da56a3973ffd62197adf2b Maintainer: takagi Status: ready -->
44
<!-- CREDITS: hirokawa,shimooka,mumumu -->
55
<refentry xml:id="function.simplexml-load-file" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -107,15 +107,15 @@
107107
<programlisting role="php">
108108
<![CDATA[
109109
<?php
110-
// The file test.xml contains an XML document with a root element
110+
// The file examples/book.xml contains an XML document with a root element
111111
// and at least an element /[root]/title.
112112
113-
if (file_exists('test.xml')) {
114-
$xml = simplexml_load_file('test.xml');
113+
if (file_exists('examples/book.xml')) {
114+
$xml = simplexml_load_file('examples/book.xml');
115115
116116
print_r($xml);
117117
} else {
118-
exit('Failed to open test.xml.');
118+
exit('Failed to open examples/book.xml.');
119119
}
120120
?>
121121
]]>
@@ -127,7 +127,7 @@ if (file_exists('test.xml')) {
127127
<![CDATA[
128128
SimpleXMLElement Object
129129
(
130-
[title] => Example Title
130+
[book] => Array
131131
...
132132
)
133133
]]>

reference/simplexml/simplexmlelement/addAttribute.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 770c6facae667218f69c8ea2715ea20f6fab32f3 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: c1f37a6c270aadbbb3da56a3973ffd62197adf2b Maintainer: takagi Status: ready -->
44
<refentry xml:id="simplexmlelement.addattribute" xmlns="http://docbook.org/ns/docbook">
55
<refnamediv>
66
<refname>SimpleXMLElement::addAttribute</refname>
@@ -65,7 +65,8 @@
6565
<para>
6666
<note>
6767
<para>
68-
この例では <literal>example.php</literal> をインクルードしていますが、これは
68+
この例では <literal>examples/simplexml-data.php</literal>
69+
をインクルードしていますが、これは
6970
<link linkend="simplexml.examples-basic">基本的な使用法</link>
7071
の最初のサンプルにある XML 文字列を参照しています。
7172
</para>
@@ -76,7 +77,7 @@
7677
<![CDATA[
7778
<?php
7879
79-
include 'example.php';
80+
include 'examples/simplexml-data.php';
8081
8182
$sxe = new SimpleXMLElement($xmlstr);
8283
$sxe->addAttribute('type', 'documentary');

reference/simplexml/simplexmlelement/addChild.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 770c6facae667218f69c8ea2715ea20f6fab32f3 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: c1f37a6c270aadbbb3da56a3973ffd62197adf2b Maintainer: takagi Status: ready -->
44
<refentry xml:id="simplexmlelement.addchild" xmlns="http://docbook.org/ns/docbook">
55
<refnamediv>
66
<refname>SimpleXMLElement::addChild</refname>
@@ -68,7 +68,8 @@
6868
<para>
6969
<note>
7070
<para>
71-
この例では <literal>example.php</literal> をインクルードしていますが、これは
71+
この例では <literal>examples/simplexml-data.php</literal>
72+
をインクルードしていますが、これは
7273
<link linkend="simplexml.examples-basic">基本的な使用法</link>
7374
の最初のサンプルにある XML 文字列を参照しています。
7475
</para>
@@ -79,7 +80,7 @@
7980
<![CDATA[
8081
<?php
8182
82-
include 'example.php';
83+
include 'examples/simplexml-data.php';
8384
8485
$sxe = new SimpleXMLElement($xmlstr);
8586
$sxe->addAttribute('type', 'documentary');

reference/simplexml/simplexmlelement/asXML.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 770c6facae667218f69c8ea2715ea20f6fab32f3 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: d6f54016d62904cfd8200604aadd5e3f0d9bad97 Maintainer: takagi Status: ready -->
44
<!-- CREDITS: hirokawa, shimooka -->
55
<refentry xml:id="simplexmlelement.asxml" xmlns="http://docbook.org/ns/docbook">
66
<refnamediv>
@@ -120,7 +120,19 @@ echo $xml->asXML();
120120
<programlisting role="php">
121121
<![CDATA[
122122
<?php
123-
// 上の XML の例から続く
123+
$string = <<<XML
124+
<a>
125+
<b>
126+
<c>text</c>
127+
<c>stuff</c>
128+
</b>
129+
<d>
130+
<c>code</c>
131+
</d>
132+
</a>
133+
XML;
134+
135+
$xml = new SimpleXMLElement($string);
124136
125137
/* <a><b><c>を探す */
126138
$result = $xml->xpath('/a/b/c');

0 commit comments

Comments
 (0)