xml-file 1
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <firstname>My name is WHAT</firstname> <lastname>My name is WHO</lastname> <body>My name is CHIKA CHIKA Slim-Shady</body> </note>
xml-file 2
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <firstname>My name is WHAT</firstname> <lastname>My name is WHO</lastname> <body><b>My name is CHIKA CHIKA Slim-Shady</b></body> </note>
question:how can i get body content in file 2
$note = simplexml_load_file("xml-file 1"); echo $note->body; //My name is CHIKA CHIKA Slim-Shady
$note = simplexml_load_file("xml-file 2");
echo $note->body; //empty
solution 1:asXML()
method will give you the "outerXML" which you then remove with strip_tags
echo strip_tags($note->body->asXml()); //My name is CHIKA CHIKA Slim-Shady
solution 2:importing the node into DOM and then getting it's nodeValue
echo dom_import_simplexml($note->body)->nodeValue;