1

I am trying to get content from a XML file, but it's not really returning everything. Here is the XML url for example:

XML Example

Extract:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="https://api.datamarket.azure.com/Data.ashx/opendata.rdw/VRTG.Open.Data/v1/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">KENT_VRTG_O_DAT</title>
  <id>https://api.datamarket.azure.com/Data.ashx/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT</id>
  <updated>2014-02-19T08:05:16Z</updated>
  <link rel="self" title="KENT_VRTG_O_DAT" href="KENT_VRTG_O_DAT" />
  <entry>
    <id>https://api.datamarket.azure.com/Data.ashx/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT('0001ES')</id>
    <title type="text"></title>
    <updated>2014-02-19T08:05:16Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="KENT_VRTG_O_DAT" href="KENT_VRTG_O_DAT('0001ES')" />
    <category term="opendata.rdw.VRTG.Open.Data.KENT_VRTG_O_DAT" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <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" />

You can see under entry->content, there is a <m:properties> with inside all information I need. However, when I print_r the contents the [content] part is just this:

 SimpleXMLElement Object
(
[@attributes] => Array
    (
        [type] => application/xml
    )

)

What am I doing wrong?

Thanks in advance.

EDIT

I have checked the previous answers, but I cant seem to find anything that works for me. This is the code I am using:

$data->entry->content->m->children('d', true)->Aantalcilinders

Solution

 $data->entry->content->children('m', true)->children('d', true)->Aantalcilinders 
Arko Elsenaar
  • 1,689
  • 3
  • 18
  • 33
  • The m prefix is a namespace. Once you know that, you'll find plenty more dupes in https://stackoverflow.com/search?q=namespace+simplexml+php. Also, never trust a SimpleXML dump due to how the engine works internally. – Gordon Feb 19 '14 at 08:08
  • I have checked a bunch of equal questions, but I just cant seem to get it to work. I have added my code example. – Arko Elsenaar Feb 19 '14 at 08:50
  • 1
    so if you know you need `children('d')` to access elements prefixed with d, why do you think you can omit it for the m namespace? – Gordon Feb 19 '14 at 09:01
  • What exactly do you mean? – Arko Elsenaar Feb 19 '14 at 09:03
  • I mean exactly what you found out now and edited as the solution ;) – Gordon Feb 19 '14 at 09:06

0 Answers0