php解析xml字符串,该怎么处理
展开全部
编写示例代码如下,经运行测试通过:
<?php
$xmlStr = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<ExportData>
<Body>
<Content>
<Id>1</Id>
<Name>Test01</Name>
<Point>40</Point>
</Content>
<Content>
<Id>2</Id>
<Name>Test02</Name>
<Point>80</Point>
</Content>
</Body>
</ExportData>
XML;
$xml = new SimpleXMLElement($xmlStr);
foreach($xml->Body->Content as $item){
echo 'ID: '.$item->Id."<br/>\n";
echo 'Name: '.$item->Name."<br/>\n";
echo 'Point: '.$item->Point."<br/><br/>\n";
}
?>
<?php
$xmlStr = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<ExportData>
<Body>
<Content>
<Id>1</Id>
<Name>Test01</Name>
<Point>40</Point>
</Content>
<Content>
<Id>2</Id>
<Name>Test02</Name>
<Point>80</Point>
</Content>
</Body>
</ExportData>
XML;
$xml = new SimpleXMLElement($xmlStr);
foreach($xml->Body->Content as $item){
echo 'ID: '.$item->Id."<br/>\n";
echo 'Name: '.$item->Name."<br/>\n";
echo 'Point: '.$item->Point."<br/><br/>\n";
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询