如何使用PHP高效解析XML数据?
- 内容介绍
- 文章标签
- 相关推荐
本文共计117个文字,预计阅读时间需要1分钟。
python加载XML字符串xml_string=
使用simplexml函数加载XMLxml=simplexml.loads(xml_string)
$xml_string="<?xml version='1.0'?> <moleculedb> <molecule name='Benzine'> <symbol>ben</symbol> <code>A</code> </molecule> <molecule name='Water'> <symbol>h2o</symbol> <code>K</code> </molecule> </moleculedb>"; //load the xml string using simplexml function $xml = simplexml_load_string($xml_string); //loop through the each node of molecule foreach ($xml->molecule as $record) { //attribute are accessted by echo $record['name'], ' '; //node are accessted by -> operator echo $record->symbol, ' '; echo $record->code, '<br />'; }
本文共计117个文字,预计阅读时间需要1分钟。
python加载XML字符串xml_string=
使用simplexml函数加载XMLxml=simplexml.loads(xml_string)
$xml_string="<?xml version='1.0'?> <moleculedb> <molecule name='Benzine'> <symbol>ben</symbol> <code>A</code> </molecule> <molecule name='Water'> <symbol>h2o</symbol> <code>K</code> </molecule> </moleculedb>"; //load the xml string using simplexml function $xml = simplexml_load_string($xml_string); //loop through the each node of molecule foreach ($xml->molecule as $record) { //attribute are accessted by echo $record['name'], ' '; //node are accessted by -> operator echo $record->symbol, ' '; echo $record->code, '<br />'; }

