php读取xml的有关问题

WBOY
Release: 2016-06-13 12:51:40
Original
785 people have browsed it

php读取xml的问题
我有一个这样的XML文件,我想把question、oid、content都输出,而且输出的格式为:
问题:542
选项:A 内容:1111111
选项:B 内容:2222222
问题:123
选项:C 内容:3333333
选项:D 内容:4444444
应该如何做?

<?xml version="1.0" encoding="utf-8"?><br />
<parent><br />
  <title>3</title><br />
  <author>admin</author><br />
  <contentall><br />
    <subject><br />
      <question>542</question><br />
      <option><br />
        <oid>A</oid><br />
        <content>1111111</content><br />
      </option><br />
      <option><br />
        <oid>B</oid><br />
        <content>2222222</content><br />
      </option><br />
    </subject><br />
    <subject><br />
      <question>123</question><br />
      <option><br />
        <oid>C</oid><br />
        <content>3333333</content><br />
      </option><br />
      <option><br />
        <oid>D</oid><br />
        <content>4444444</content><br />
      </option><br />
    </subject><br />
  </contentall><br />
</parent><br />
Copy after login

xml php
------解决方案--------------------
$s =
<?xml  version="1.0" encoding="utf-8"?><br>
<parent><br>
  <title>3</title><br>
  <author>admin</author><br>
  <contentall><br>
    <subject><br>
      <question>542</question><br>
      <option>
<br>
        <oid>A</oid><br>
        <content>1111111</content><br>
      </option>
<br>
      <option>
<br>
        <oid>B</oid><br>
        <content>2222222</content><br>
      </option>
<br>
    </subject><br>
    <subject><br>
      <question>123</question><br>
      <option>
<br>
        <oid>C</oid><br>
        <content>3333333</content><br>
      </option>
<br>
      <option>
<br>
        <oid>D</oid><br>
        <content>4444444</content><br>
      </option>
<br>
    </subject><br>
  </contentall><br>
</parent><br>
XML;<br>
<br>
$xml = simplexml_load_string($s); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template