Jump to content

Need help accessing xml elements from simplexml


frobak

Recommended Posts

Hi, having some issues getting to the values of an xml document using simplexmlelement

 

Basically, whatever i do, i cant seem to get the values

 

heres the xml data

  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="StdData">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="MAKE" type="xs:string" minOccurs="0" />
                <xs:element name="MODEL" type="xs:string" minOccurs="0" />
                <xs:element name="CC" type="xs:string" minOccurs="0" />
                <xs:element name="VIN" type="xs:string" minOccurs="0" />
                <xs:element name="ENGINE_NUMBER" type="xs:string" minOccurs="0" />
                <xs:element name="REG_DATE" type="xs:string" minOccurs="0" />
                <xs:element name="MANUF_DATE" type="xs:string" minOccurs="0" />
                <xs:element name="COLOUR" type="xs:string" minOccurs="0" />
                <xs:element name="VEHICLE_MASS" type="xs:string" minOccurs="0" />
                <xs:element name="VEHICLE_SEATS" type="xs:string" minOccurs="0" />
                <xs:element name="VEHICLE_V5c_DATE" type="xs:string" minOccurs="0" />
                <xs:element name="VEHICLE_NOISE_STATIONARY" type="xs:string" minOccurs="0" />
                <xs:element name="VEHICLE_NOISE_DRIVE_BY" type="xs:string" minOccurs="0" />
                <xs:element name="VEHICLE_NOISE_ENGINE" type="xs:string" minOccurs="0" />
                <xs:element name="WHEELPLAN_DESC" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element name="EnhancedData">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="fldmanLName" type="xs:string" minOccurs="0" />
                <xs:element name="fldmodLName" type="xs:string" minOccurs="0" />
                <xs:element name="fldmodverNo" type="xs:string" minOccurs="0" />
                <xs:element name="fldderLName" type="xs:string" minOccurs="0" />
                <xs:element name="fldderverno" type="xs:string" minOccurs="0" />
                <xs:element name="fldbstLName" type="xs:string" minOccurs="0" />
                <xs:element name="flddooCountLName" type="xs:string" minOccurs="0" />
                <xs:element name="fldgeacountLname" type="xs:string" minOccurs="0" />
                <xs:element name="fldtratypeLname" type="xs:string" minOccurs="0" />
                <xs:element name="fldEngineCode" type="xs:string" minOccurs="0" />
                <xs:element name="fldGearboxCode" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <NewDataSet xmlns="">
      <StdData diffgr:id="StdData1" msdata:rowOrder="0">
        <MAKE>CITROEN             </MAKE>
        <MODEL>C3 SX  

 

Basically, i need to get the make and model of the car, which is showing just above.

 

heres the php

 

// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, '');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, '');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (LOGIN)
$postresponse = curl_exec ($ch);
echo $postresponse;

// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL, '');

// EXECUTE 2nd REQUEST (xml response)
$getresponse = curl_exec ($ch);
$xml = new SimpleXMLElement($getresponse);
echo $xml->diffgram->MAKE;

// CLOSE THE SESSION
curl_close($ch);

 

ive been trying for a coupel of days now, need some help. how can i access those xml elements only? any ideas

 

cheers

It's a bit more complicated than that because you have to deal with XML namespaces: the bit before the colon in the tag name and the URL associated with it.

$xml->children("diffgr", true)->diffgram->children("")->NewDataSet->StdData->MAKE

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.