My problem is that i am parsing an XML file and this file contain some information that i don\'t want to exporting as JSON data. In my case i want a function that return the jso
Remove every attribute you don't want just before encoding json:
public function ParseXML ($url) {
$fileContents= file_get_contents($url);
// Remove tabs, newline, whitespaces in the content array
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$myXml = simplexml_load_string($fileContents);
//--------------
unset($myXml['@attributes']);
unset($myXml['channel']);
unset($myXml['image']);
//--------------
$json = json_encode($myXml);
return $json;
}
or if you only need the item:
public function ParseXML ($url) {
$fileContents= file_get_contents($url);
// Remove tabs, newline, whitespaces in the content array
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$myXml = simplexml_load_string($fileContents);
//--------------
$json = json_encode($myXml['item']);
return $json;
}