Reputation: 153
I have a field in my xml like this :
<radar snb="09H0000" ver="1023" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="icomsData.xsd">
How can get the variable "xsi:noNamespaceSchemaLocation"
My code to get "snb" and "ver" works fine but not for the 2 others :/
My code :
$fichier = 'test.xml';
$radar = simplexml_load_file($fichier);
echo '</br> Radar :
</br> snb : <strong>'.$radar['snb'].' </strong>ver : <strong>'.$radar['ver'].'</strong> xmlns:xsi : <strong>'.$radar['xmlns:xsi'].' </strong> xsi:noNamespaceSchemaLocation : <strong>'.$radar['xsi:noNamespaceSchemaLocation'].'</strong>';
I tried with " and ' it doesn't change anything.
Upvotes: 0
Views: 79
Reputation: 2319
you can use this code to access variables in xml file :
<?php
$xmlFile = 'test.xml';
$xml = simplexml_load_file($xmlFile);
$radarAttr = $xml->attributes();
$noNamespaceSchemaLocation = $xml->attributes('xsi', true)->noNamespaceSchemaLocation->__tostring();
$radarSnb = $radarAttr['snb']->__tostring();
$radarVer = $radarAttr['ver']->__tostring();
foreach($xml->log as $log) {
$LogAttrs = $log->attributes();
$logTs = $LogAttrs['ts']->__tostring();
$logVb = $LogAttrs['vb']->__tostring();
$site = $log->site->__tostring();
$evArray = $log->ev;
foreach($evArray as $ev) {
$EvAttrs = $ev->attributes();
$evTs = $EvAttrs['ts']->__tostring();
$evData = $ev->children();
$ev_sp = $evData->sp->__tostring();
$ev_lg = $evData->lg->__tostring();
$ev_dir = $evData->dir->__tostring();
}
}
Upvotes: 1
Reputation: 702
For this solution you would need to take these step as follows
Upvotes: 0