如何从xml文件中检索日期

时间:2012-04-02 19:16:45

标签: php xml wikipedia-api

这是我的xml文件,我不知道如何使用php从xml文件中检索值,如何从xml文件中检索信息。如果你知道请帮助我。

  my xml file:
  see:http://en.wikipedia.org/w/api.php?  format=xml&action=query&titles=vikram&prop=revisions&rvprop=content


  <api>
  <query>
  <normalized>
   <n from="vikram" to="Vikram"/>
   </normalized>
   <pages>
   <page pageid="1034501" ns="0" title="Vikram">
    <revisions>
    <rev xml:space="preserve">
    '''Vikram''' may refer to: *[[Vikram (name)]], a male name in the Hindu  
    community *[[Vikramāditya]], a legendary king of India **Vikram, a character
   in   ''[[Baital Pachisi]]'', identified with Vikramāditya **[[Vikram Samvat]]
  (Vikram's Era, "V.S." or "B.S"), a popularly used calendar in India and the 
  official calendar of Nepal, established by Vikramaditya *[[Vikram Pandit]], 
  CitiGroup CEO *[[Vikram (actor)]], Vikram Kennedy, a Tamil-language Indian 
 film actor *[[Vikram Sarabhai]], an Indian scientist *[[Vikram 
 (film)|''Vikram'' (film)]], a 1986 Tamil-language Indian film *[[Vikram (1986 
 Telugu film)|''Vikram'' (1986 Telugu film)]], a 1986 Telugu-language Indian 
 film *[[Vikram Seth]], a bestselling author of Indian origin ;See also: *
 {{lookfrom|Vikram}} *{{intitle|Vikram}} {{disambig}}
 </rev>
 </revisions>
 </page>
 </pages>
 </query>
 </api>

2 个答案:

答案 0 :(得分:0)

您可以使用PHP的原生DomDocumentSimpleXML

答案 1 :(得分:0)

您可以使用xml_parse_into_struct()函数轻松解析XML。

<?php
$simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
?>

source