使用PHP XML DOM解析和比较xml值

时间:2011-11-03 17:45:23

标签: php xml dom

我正在尝试使用PHP的DOM XML比较节点值和解析xml属性值。

以下是我在网页上的内容,但我不再收到结果或错误。

PHP:

        <?PHP
        error_reporting(E_ALL);
        ini_set("display_errors", 1);


        //PRODUCT URL
        $xml_url = "http://<servername>/services/info?storeId=2;


        //LOCAL TEST URL
        //$xml_url = "testXML.xml";


        $xmlDoc = new DOMDocument();

        $xmlDoc->load($xml_url);

        //THIS IS WHERE MY ISSUE IS (I THINK)
         $errorCheck = $xmlDoc->getElementsByTagName( "testcode"" );
         $errorValue = $errorCheck->item(0)->nodeValue;

        if ($errorValue != "1"){

            //loop and show data 

 $grads = $xmlDoc->getElementsByTagName( "$grads" );
  foreach( $grads as $grad )
  {

  $students = $grad->getElementsByTagName( "student" );
  $student = $students>item(0)->nodeValue;

  $times = $grad->getElementsByTagName( "time" );
  $time =  $times->item(0)->nodeValue;


  echo "<tr><td>".$student."</td><td>".$time."</td></tr>";
  }



        }else{



                ?>
    <H1> Show an html message</H1>
    <?


        }

        ?>

这是我的测试XML:

<response>
    <testcode>0</testcode>
    <grad student="mike" time="10:00am"/>
    <grad student="Bob" time="11:00am" />
    <grad student="TOM" time="11:30am" />
    <grad student="Greg" time="1:00pm" />
</response>

0 个答案:

没有答案