1

When I use simplexml_load_string in php like this:

$response = '<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
    <response xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
        <result code="1000">
            <msg>Command completed successfully</msg>
        </result>
        <resData xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
            <domain:chkData xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
                <domain:cd>
                    <domain:name normalized_name="dsfdsfdsfsdfdffdg"
                                 canonized_name="dsfdsfdsfsdfdffdg" tld="ir" avail="1">
                        dsfdsfdsfsdfdffdg.ir
                    </domain:name>
                </domain:cd>
            </domain:chkData>
        </resData>
        <trID>
            <clTRID>TEST-14922533391168726112</clTRID>
            <svTRID>IRNIC_2017-04-15T15:18:59+04:30_epi</svTRID>
        </trID>
    </response>
</epp>';
$a = simplexml_load_string($response);
var_dump($a);

When I display $a I have no resData value, and I missing this property. How can I fix this?

2
  • 1
    It's the namespace problem. look here - eval.in/776816 I've written some first steps Commented Apr 15, 2017 at 11:29
  • If you want to get any value, you can register namespace and use Xpath Commented Apr 15, 2017 at 11:36

2 Answers 2

1

You were using wrong variable $response which is not at all initialized. Use $result which contains your complete html string instead of $response

Try this. Code demo

<?php
$result = '<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
    <response xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
        <result code="1000">
            <msg>Command completed successfully</msg>
        </result>
        <resData xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
            <domain:chkData xmlns:domain="http://epp.nic.ir/ns/domain-1.0">
                <domain:cd>
                    <domain:name normalized_name="dsfdsfdsfsdfdffdg"
                                 canonized_name="dsfdsfdsfsdfdffdg" tld="ir" avail="1">
                        dsfdsfdsfsdfdffdg.ir
                    </domain:name>
                </domain:cd>
            </domain:chkData>
        </resData>
        <trID>
            <clTRID>TEST-14922533391168726112</clTRID>
            <svTRID>IRNIC_2017-04-15T15:18:59+04:30_epi</svTRID>
        </trID>
    </response>
</epp>';
$a = simplexml_load_string($result);
var_dump($a);
Sign up to request clarification or add additional context in comments.

Comments

0

Thank @splash58.
I should use namespace like this:

$a = simplexml_load_string($result);
$ns = $a->getNamespaces(true);
var_dump($a->response->resData->children($ns['domain']));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.