Hello Reader's!, If you are developing the website that takes input in XML and you want it to convert in PHP, Then you have to use some of the library extensions to do so.
Let suppose you have the XML as given below:-
<tag1Version="1.0">
<tag2>
<main>
<body Id="id:pass" />
<content name="hearaman" age="24" />
</body>
</tag2>
</tag1>
The syntax looks something like this for your example
$xml = new SimpleXMLElement($xmlString);
echo $xml->tag1->tag2->main['Id'];
echo $xml->tag2->body ->content ['name'];
// or...........
foreach ($xml->tag2->body as $element) {
foreach($element as $key => $val) {
echo "{$key}: {$val}";
}
}
You can also have to details of this extension from here
And another way to achieve it is as below:-
$xml = simplexm_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_;encode($xml);
$array = json_decode($json,TRUE);
0 Comment(s)