0

ドキュメントの解析/読み取りで何が間違っているのかよくわかりませんxml。私の推測では、それは標準化されておらず、文字列から何かを読み取るには別のプロセスが必要になるでしょう。

もしそうなら、誰かが xml をどのように読むかを知りたいと思います。これが私が持っているものであり、私がしていることです。

example.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="someurl.php"?>
<response>
 <status>Error</status>
 <error>The error message I need to extract, if the status says Error</error>
</response>

read_xml.php

<?php
 $content = 'example.xml';
 $string = file_get_contents($content);
 $xml = simplexml_load_string($string);
 print_r($xml);
?>

から結果が返されませんprint_r。次のような、より標準的なもの
に切り替えました。xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

...そしてうまくいきました。したがって、取得元のソースから返された非標準形式が原因であると確信しています。

<status>および<error>タグを抽出するにはどうすればよいですか?

4

2 に答える 2