HuyPV
Wednesday, August 22, 2012
$s = <<<STR
<?xml version="1.0" encoding="UTF-8"?>
<store>
<owner name="huypv"></owner>
<book id="b#ffdg01">
<page i="12">
<content>
<![CDATA[ Taj vj sao laj th3?! ]]>
</content>
</page>
</book>
<book id="b#ffdg02">
<page i="13">
<content>
<![CDATA[ Taj vj sao laj th3 v2.0?! ]]>
</content>
</page>
</book>
<extra>
<year>2012</year>
<gold>true</gold>
<silver>60%</silver>
</extra>
</store>
STR;
function getInnerXML($xml) {
$innerXML = '';
foreach (dom_import_simplexml($xml)->childNodes as $child) {
$innerXML .= $child->ownerDocument->saveXML($child);
}
return $innerXML;
}
$xml = simplexml_load_string($s);
# get Taj vj sao laj th3 v2.0?!
echo (string)$xml->book[1]->page->content;
# get 60%
echo $xml->extra[0]->silver;
# get huypv
$a = $xml->owner->attributes();
var_dump((string)$a['name']);
# get innerXML book-0
var_dump(getInnerXML($xml->book[0]));
var_dump($xml->book[0]->asXML());
Title:
php simple xml get inner xml
Description:
$s = <<<STR <?xml version="1.0" encoding="UTF-8"?> <store> <owner name="huypv"...
...
Rating:
4