Jump to content

XML Parse Value


Go to solution Solved by 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'];
	
	
?>
Edited by MoFish
Link to comment
https://forums.phpfreaks.com/topic/291485-xml-parse-value/#findComment-1492944
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.