mirror of
https://github.com/php/doc-ja.git
synced 2026-04-26 17:38:12 +02:00
42faf122ea
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@197947 c90b9560-bf6c-de11-be94-00142212c4b1
112 lines
3.7 KiB
XML
112 lines
3.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision: 1.5 $ -->
|
|
<!-- EN-Revision: 1.11 Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: shimooka -->
|
|
<refentry id='function.simplexml-load-file'>
|
|
<refnamediv>
|
|
<refname>simplexml_load_file</refname>
|
|
<refpurpose>
|
|
XMLファイルをパースし、オブジェクトに代入する
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>説明</title>
|
|
<methodsynopsis>
|
|
<type>object</type><methodname>simplexml_load_file</methodname>
|
|
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>class_name</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>options</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
この関数は、<parameter>filename</parameter>で指定されたファイルの中の整形式の
|
|
XMLドキュメントを<literal>SimpleXMLElement</literal>クラスの
|
|
<type>オブジェクト</type>に変換します。
|
|
ファイルアクセス時またはパース時にエラーが発生した場合、この関数は &false; を返します。
|
|
</para>
|
|
<para>
|
|
<function>simplexml_load_file</function>
|
|
が指定されたクラスのオブジェクトを返すようにするためにオプションの
|
|
<parameter>class_name</parameter> パラメータを使用することができます。
|
|
そのクラスは、<type>SimpleXMLElement</type>
|
|
クラスを継承していなければなりません。
|
|
</para>
|
|
<para>
|
|
PHP 5.1.0 と Libxml 2.6.0 から、<link
|
|
linkend="libxml.constants">追加の Libxml パラメータ</link>
|
|
を指定するために <parameter>options</parameter>
|
|
を使用することもできます。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Libxml 2 は URI をエスケープしませんので、例えば URI パラメータ
|
|
<literal>a</literal> に <literal>b&c</literal> を渡したい場合、
|
|
<literal>simplexml_load_file(rawurlencode('http://example.com/?a=' .
|
|
urlencode('b&c')))</literal>
|
|
をしてコールする必要があります。PHP 5.1.0 以降では、これをする必要は
|
|
ありません。PHP が自動的に行います。
|
|
</para>
|
|
</note>
|
|
<para>
|
|
<example>
|
|
<title>XMLドキュメントをパースする</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// The file test.xml contains an XML document with a root element
|
|
// and at least an element /[root]/title.
|
|
|
|
if (file_exists('test.xml')) {
|
|
$xml = simplexml_load_file('test.xml');
|
|
|
|
var_dump($xml);
|
|
} else {
|
|
exit('Failed to open test.xml.');
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
このスクリプトは成功時に以下のよに出力します。
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
SimpleXMLElement Object
|
|
(
|
|
[title] => Example Title
|
|
...
|
|
)
|
|
]]>
|
|
</screen>
|
|
<simpara>
|
|
この時点で、<literal>$xml->title</literal> としたり、他の全ての要素にアクセス
|
|
することができます。
|
|
</simpara>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<function>simplexml_load_string</function>も参照してください。
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|