PHP XML Crossdomain如何插入Markup?

时间:2012-10-29 07:09:18

标签: php xml cross-domain

嗨,我有点问题,

我正在检索这样的XML:

    // create new document object
    $dom_object = new DOMDocument();
    // load xml file
    $dom_object->load("http://www.mhs2000.de/hpm/v6/machinelist-master.php?hid=1007&lang=de&GroupID=01002");

    $item = $dom_object->getElementsByTagName("product");

        foreach( $item as $value )
    {

    $nos = $value->getElementsByTagName("MachineNo");
    $no  = $nos->item(0)->nodeValue;
    $machineno = str_replace( "1007-", "", $no );

    $herstellers = $value->getElementsByTagName("Make");
    $hersteller  = $herstellers->item(0)->nodeValue;


    $types = $value->getElementsByTagName("Type");
    $type  = $types->item(0)->nodeValue;

    $labels = $value->getElementsByTagName("NewIn");
    $label  = $labels->item(0)->nodeValue;

    $controltypes = $value->getElementsByTagName("ControlType");
    $controltype  = $controltypes->item(0)->nodeValue;


    $bildurls = $value->getElementsByTagName("BildUrl");
    if($bildurls->length == 0)
    {
        $bildurl = ("/wp-content/themes/framework/images/logo.jpg");
    }
    else
    $bildurl  = $bildurls->item(0)->nodeValue;

    $tdetailsformats = $value->getElementsByTagName("tdetailsformat");
    $tdetailsformat  = $tdetailsformats->item(0)->nodeValue;
    $tdetailsformat = str_replace( "|", " ", $tdetailsformat );
    $tdetailsformat = str_replace( "%", "", $tdetailsformat );


    echo "<div class=\"row span_16\">";
    echo "<div class=\"col span_4 clr\">";
    echo "<a href=\"$bildurl\">";
    echo "<img src=\"$bildurl\" class=\"thumb\">";
    echo "</a>";
    echo "</div><div class=\"col span_12 clr\">";
    echo "$machineno $hersteller - $type - $label - $controltype - $tdetailsformat";
    echo "</div>";
    echo "</div>";
    }

所以每个人都可以正常工作,但是我需要做些什么来围绕结果制作一个表?

当我打开标签时,它会显示在我的结果下方。

<div class="col span_12 clr">6056 HELLER - BEA 05 - 1986 - CNC - x-Weg 500 mm y-Weg 400 mm z-Weg 560 mm Spindeldurchmesser 70 mm Aufnahme SK 40 </div>
<table></table>

提前致谢。

1 个答案:

答案 0 :(得分:1)

在foreach循环之前打开表标记:

  <table>
    <tr>
      <td>MachineNo</td>
      <td>Make</td>
       .... Add rest of the header items like above
    </tr>

启动foreach:

    foreach( $item as $value )
    {        
       echo "<tr>";

       $nos = $value->getElementsByTagName("MachineNo");
       $no  = $nos->item(0)->nodeValue;
       $machineno = str_replace( "1007-", "", $no );

       echo "<td>$machineno</td>";
       //.. Likewise, add rest of the td's after processing each node

      echo "</tr>";

     }

关闭你的桌子:

     </table>