-1

私の XML ファイルには次のコードがあります。

<Object>
  <hasOLE>false</hasOLE> 
  <Attribute Name="Absolute Number">
    <Value>1</Value> 
  </Attribute>
  <Attribute Name="Object Number">
    <Value>1</Value> 
  </Attribute>
  <Attribute Name="Object Heading">
    <Value>Introduction</Value> 
  </Attribute>
  <Attribute Name="Object Text">
    <Value /> 
  </Attribute>
</Object>

PHPで属性を読み取るにはどうすればよいですか?

4

1 に答える 1

0

使用simplexml_load_string:

$string = '<Object>
    <hasOLE>false</hasOLE> 
    <Attribute Name="Absolute Number">
        <Value>1</Value> 
    </Attribute>
    <Attribute Name="Object Number">
        <Value>1</Value> 
    </Attribute>
    <Attribute Name="Object Heading">
        <Value>Introduction</Value> 
    </Attribute>
    <Attribute Name="Object Text">
        <Value /> 
    </Attribute>
</Object>';

$xml = simplexml_load_string( $string );
// Or $xml = simplexml_load_file( $filename ); if it's inside a file.

そして、次のように簡単にアクセスします。

echo $xml->Attribute->attributes(); //Absolute Number 
echo $xml->Attribute->Value;        // 1
于 2012-10-30T11:08:34.090 に答える