<?xml version="1.0" encoding="gbk" ?>
- <xml>
<result>1</result>
<total>277</total>
<num>30</num>
<start>0</start>
<xyString>11419415,3059132,11436404,3055803</xyString>
<searchType>round</searchType>
- <list>
+ <I0>
<id>0027_47371</id>
<title>鹏鹏小吃</title>
<atitle>鹏鹏小吃</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11427798 3058375</gc>
<bus>1</bus>
<intro />
<aintro />
</I0>
- <I1>
<id>0027_164307</id>
<title>健康快餐(江汉桥小学西北)</title>
<atitle>健康快餐(江汉桥小学西北)</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11426761 3056654</gc>
<bus>1</bus>
<intro />
<aintro />
</I1>
- <I2>
<id>0027_109608</id>
<title>福建蒸饺王大兴路分店</title>
<atitle>福建蒸饺王大兴路分店</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11429130 3056882</gc>
<bus>1</bus>
<intro />
<aintro />
</I2>
- <I3>
<id>0027_51453</id>
<title>永和大王(江汉路)</title>
<atitle>永和大王(江汉路)</atitle>
<aaddr>江汉步行街</aaddr>
<addr>江汉步行街</addr>
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11429024 3058214</gc>
<bus>1</bus>
<intro />
<aintro />
</I3>
- <I4>
<id>0027_109000</id>
<title>李记特色小吃</title>
<atitle>李记特色小吃</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11426940 3056838</gc>
<bus>1</bus>
<intro />
<aintro />
</I4>
<list>
<xml>怎么实现 从数据库表中读出以上的数据 现实这种格式 <字段名>字段值<\字段名>
- <xml>
<result>1</result>
<total>277</total>
<num>30</num>
<start>0</start>
<xyString>11419415,3059132,11436404,3055803</xyString>
<searchType>round</searchType>
- <list>
+ <I0>
<id>0027_47371</id>
<title>鹏鹏小吃</title>
<atitle>鹏鹏小吃</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11427798 3058375</gc>
<bus>1</bus>
<intro />
<aintro />
</I0>
- <I1>
<id>0027_164307</id>
<title>健康快餐(江汉桥小学西北)</title>
<atitle>健康快餐(江汉桥小学西北)</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11426761 3056654</gc>
<bus>1</bus>
<intro />
<aintro />
</I1>
- <I2>
<id>0027_109608</id>
<title>福建蒸饺王大兴路分店</title>
<atitle>福建蒸饺王大兴路分店</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11429130 3056882</gc>
<bus>1</bus>
<intro />
<aintro />
</I2>
- <I3>
<id>0027_51453</id>
<title>永和大王(江汉路)</title>
<atitle>永和大王(江汉路)</atitle>
<aaddr>江汉步行街</aaddr>
<addr>江汉步行街</addr>
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11429024 3058214</gc>
<bus>1</bus>
<intro />
<aintro />
</I3>
- <I4>
<id>0027_109000</id>
<title>李记特色小吃</title>
<atitle>李记特色小吃</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11426940 3056838</gc>
<bus>1</bus>
<intro />
<aintro />
</I4>
<list>
<xml>怎么实现 从数据库表中读出以上的数据 现实这种格式 <字段名>字段值<\字段名>
简单写了下解析
test.xml
<?xml version="1.0" encoding="gbk" ?>
<xml>
<result>1</result>
<total>277</total>
<num>30</num>
<start>0</start>
<xyString>11419415,3059132,11436404,3055803</xyString>
<searchType>round</searchType>
<list>
<I0>
<id>0027_47371</id>
<title>鹏鹏小吃</title>
<atitle>鹏鹏小吃</atitle>
<aaddr ></aaddr>
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11427798 3058375</gc>
<bus>1</bus>
<intro />
<aintro />
</I0>
<I1>
<id>0027_164307</id>
<title>健康快餐(江汉桥小学西北)</title>
<atitle>健康快餐(江汉桥小学西北)</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11426761 3056654</gc>
<bus>1</bus>
<intro />
<aintro />
</I1>
<I2>
<id>0027_109608</id>
<title>福建蒸饺王大兴路分店</title>
<atitle>福建蒸饺王大兴路分店</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11429130 3056882</gc>
<bus>1</bus>
<intro />
<aintro />
</I2>
<I3>
<id>0027_51453</id>
<title>永和大王(江汉路)</title>
<atitle>永和大王(江汉路)</atitle>
<aaddr>江汉步行街</aaddr>
<addr>江汉步行街</addr>
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11429024 3058214</gc>
<bus>1</bus>
<intro />
<aintro />
</I3>
<I4>
<id>0027_109000</id>
<title>李记特色小吃</title>
<atitle>李记特色小吃</atitle>
<aaddr />
<addr />
<category>50300</category>
<navigator>快餐厅餐饮相关</navigator>
<tel />
<pic_urlS />
<gc>11426940 3056838</gc>
<bus>1</bus>
<intro />
<aintro />
</I4>
</list>
</xml><?php
$dom = new DOMDocument();
$dom ->load('test.xml');
$xml = $dom ->getElementsByTagName('xml');
foreach ($xml as $xmlVal){
$results = $xmlVal->getElementsByTagName('result');
$result = $results->item(0)->nodeValue;
$totals = $xmlVal->getElementsByTagName('total');
$total = $totals->item(0)->nodeValue;
$lists = $xmlVal->getElementsByTagName('list');
$list = $lists->item(0)->nodeValue;
var_dump( $list);
}
$str='<result>'.$result.'</result>'.'<total>'.$total.'</total>';
echo htmlspecialchars($str);
?>
结果:
string '
0027_47371
鹏鹏小吃
鹏鹏小吃
50300
快餐厅餐饮相关
11427798 3058375
1
0027_164307
健康快餐(江汉桥小学西北)
健康快餐(江汉桥小学西北)
50300
快餐厅餐饮相关
11426761 3056654
1
0027_109608
福建蒸饺王大兴路分店
福建蒸饺王大兴路分店
50300
快餐厅餐饮相关
11429130 3056882
1
0027_51453
永和大王(江汉路)
永和大王(江汉路)
江汉步行街
江汉步行街
50300
快餐�'... (length=676)<result>1</result><total>277</total>
当然格式比你的复杂点
<row1>
<字段1>值1</字段1>
<字段2>值2</字段2>
<字段3>值3</字段3>
<字段4>值4</字段4>
</row1>
<row2>
<字段1>值1</字段1>
<字段2>值2</字段2>
<字段3>值3</字段3>
<字段4>值4</字段4>
</row2>……… ……用 mysql_fetch_field 和 mysql_fetch_row怎么结合使用才能实现(不一定用这个 实现就好 呵呵