Jump to content

XML Parse Value


MoFish

Recommended Posts

Hi,

 

I'm trying to return the value of avail="0" from the following XML file using simplexml_load_string.

  <response>
    <result code="1000">
      <msg>Command completed successfully</msg>
    </result>
    <resData>
      <domain:chkData
        xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
        xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
        <domain:cd>
          <domain:name avail="0">www.testing.co.uk</domain:name>
        </domain:cd>
      </domain:chkData>
    </resData>

I have it working where I can access the www.testing.co.uk value using the following:

echo $xml->response->resData->children('domain', true)->chkData->children('domain', true)->cd->children('domain', true)->name;

But am not sure how to access the avail value? I thought the following would have worked by adding ['avail'] onto the end, but appear to be missing something.

echo $xml->response->resData->children('domain', true)->chkData->children('domain', true)->cd->children('domain', true)->name['avail'];

Any help much appreciated.

 

MoFish

Link to comment
https://forums.phpfreaks.com/topic/291485-xml-parse-value/
Share on other sites

Still cant figure this out.

<?php 

	$result = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<epp xmlns='urn:ietf:params:xml:ns:epp-1.0'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:schemaLocation=''>
  <response>
    <result code='1000'>
      <msg>Command completed successfully</msg>
    </result>
    <resData>
      <domain:chkData
        xmlns:domain='urn:ietf:params:xml:ns:domain-1.0'
        xsi:schemaLocation='urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd'>
        <domain:cd>
          <domain:name avail='0'>bob.co.uk</domain:name>
        </domain:cd>
      </domain:chkData>
    </resData>
    <extension>
      <domain-nom-ext:chkData abuse-limit='4990'
        xmlns:domain-nom-ext=''
        xsi:schemaLocation=''/>
    </extension>
  </response>
</epp>";
	
	
	$xml = simplexml_load_string($result);
	
	// this gets the domain name
	echo $xml->response->resData->children('domain', true)->chkData->children('domain', true)->cd->children('domain', true)->name;
	
	// now get the avail value?
	echo $xml->response->resData->children('domain', true)->chkData->children('domain', true)->cd->children('domain', true)->name->name['avail'];
	
	
?>
Link to comment
https://forums.phpfreaks.com/topic/291485-xml-parse-value/#findComment-1492944
Share on other sites

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.