关于PHP解析XML文件的..

来源:百度知道 编辑:UC知道 时间:2024/06/30 01:12:29
高悬赏..

先贴上PHP代码清单..
<?php

$info = simplexml_load_file('maints.xml');

print_r($info);

$LineNum = $info->tblFlight[0]->LineNum;

echo $LineNum;

foreach ($info->LeapsoulInfo as $tblFlight)
{
echo $tblFlight->LineNum."<br/>";
echo $tblFlight->FlightNo."<br/>";
echo $tblFlight->DepTime."<br/>";
echo $tblFlight->ArvTime."<br/>";
echo $tblFlight->Meal."<br/>";
echo $tblFlight->PlaneStyle."<br/>";
echo $tblFlight->HasStop."<br/>";
echo $tblFlight->OrgCity."<br/>";
echo $tblFlight->DstCity."<br/>";
}

foreach($info->xpath('//LineNum') as $value) {
echo $value.'<br />';
}

?>

朋友,你不能在dom操作里边用数组的方法直接调用属性和vlaue
推荐你看下dom手册和php手册,当然如有需要我可以给你发一份到邮箱
你可以用dom的操作来读取
<?php
$doc=new DOMDocument();
$doc->load("liuyan.xml");
$liuyan=$doc->getElementsByTagName("line");
foreach($liuyan as $ly)
{

$id=$ly->getAttribute("id");

$nicker=$ly->getElementsByTagName("nicker");
$nicker=$nicker->item(0)->nodeValue;
$nicker=iconv("utf-8","gb2312",$nicker);

$email=$ly->getElementsByTagName("email");
$email=$email->item(0)->nodeValue;

$url=$ly->getElementsByTagName("url");
$url=$url->item(0)->nodeValue;

$content=$ly->getElementsByTagName("content");
$content=$content->item(0)->nodeValue;
$content=iconv("utf-8","gb2312",$content);

$cr