Hallo mensen

Ik loop tegen het volgende probleem aan.
De query, mijn code ziet er als volgt uit:

<?php
echo <<<EOF
<table>
<tr>
<th>Kenteken</th>
<th>Laadvermogen</th>
<th>Merk</th>
<th>Milieuclassificatie</th>
<th>Nevenbrandstof</th>
</tr>

EOF;
//$xml = new SimpleXMLElement('https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT', null, true);
$xml = simplexml_load_file("https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT");
$xml->registerXPathNamespace('m','http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
foreach ($xml->xpath('//m:properties') as $title)
{
$row = simplexml_load_string($title->asXML());
$row->registerXPathNamespace('d', 'http://schemas.microsoft.com/ado/2007/08/dataservices');
$v = $row->xpath('//d:Kenteken[. ="0001ES"]');
if($v[0]){
echo <<<EOF

<tr>
<td>{$title->Kenteken}</td>
<td>{$title->Laadvermogen}</td>
<td>{$title->Merk}</td>
<td>{$title->Milieuclassificatie}</td>
<td>{$title->Nevenbrandstof}</td>
</tr>

EOF;
}
}
?>

Wat ik wil is dat als het kenteken "0001ES" is hij alle gegevens van die kenteken laat zien. Ik heb toen straks een code gehad waar hij dus wel alleen "0001ES" laat zien maar ik kon toen niet bij de andere gegevens die bij die kenteken horen.

Ik heb al verschillende constructies van internet afgehaald waaronder deze die ik nu heb. Misschien mis ik iets heel simpels maar ik hoop dat iemand mij kan helpen.

om even een kort voorbeeld te geven hoe de .xml file eruit ziet(kan ook via de URL)
<entry>
  <content>
    <m:properties>
        <d:Aantalcilinders m:type="Edm.Int16">4</d:Aantalcilinders>
        <d:Aantalstaanplaatsen m:type="Edm.Int16" m:null="true" />
        <d:Aantalzitplaatsen m:type="Edm.Int16" m:null="true" />
        <d:BPM m:type="Edm.Int32" m:null="true" />
        <d:Brandstofverbruikbuitenweg m:type="Edm.Decimal" m:null="true" />
        <d:Brandstofverbruikgecombineerd m:type="Edm.Decimal" m:null="true" />
        <d:Brandstofverbruikstad m:type="Edm.Decimal" m:null="true" />
        <d:Catalogusprijs m:type="Edm.Int32" m:null="true" />
    </m:properties>
  </content>
</entry>



Ik denk dat je de namespace niet moet registeren op $row maar op $title
Ik heb het geprobeerd maar dat lost in dit geval het probleem niet op. Misschien dat het gewoon iets heel simpels is maar ik kijk er nu al te lang naar en kan het niet vinden.
Het is dus de bedoeling dat hij alle gegevens erbij pakken die bij dat kenteken horen die er nu in staat.
Ik zou in dit geval de PHP DOM gebruiken, daar kan je veel meer als met SimpleXML.
<?php
$xml = new DOMDocument();
$xml -> load("https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT");
$xp = new DOMXPath($xml);
$xp->registerNamespace('m','http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
$xp->registerNamespace('d', 'http://schemas.microsoft.com/ado/2007/08/dataservices');
$props = $xp->query('//m:properties/d:Kenteken[. = "0001ES"]')->item(0)->parentNode;
echo $props->getElementsByTagNameNS('http://schemas.microsoft.com/ado/2007/08/dataservices', 'Kenteken')->item(0)->nodeValue . '<br>' .
		$props->getElementsByTagNameNS('http://schemas.microsoft.com/ado/2007/08/dataservices', 'Laadvermogen')->item(0)->nodeValue . '<br>' .
		$props->getElementsByTagNameNS('http://schemas.microsoft.com/ado/2007/08/dataservices', 'Merk')->item(0)->nodeValue . '<br>' .
		$props->getElementsByTagNameNS('http://schemas.microsoft.com/ado/2007/08/dataservices', 'Nevenbrandstof')->item(0)->nodeValue . '<br>';
?>
Super bedankt, hier kan ik wat mee.

Reageren