문제

I have run into a minor problem. I am using Zoho CRM API and it returns me an XML in a format like this:

<response uri="/crm/private/xml/Contacts/getRecords">
    <result>
        <Contacts>
            <row no="1">
                <FL val="Contact Owner">
                    <![CDATA[ Kristo Vaher ]]>
                </FL>
                <FL val="Lead Source">
                    <![CDATA[ Partner ]]>
                </FL>
            </row>
        </Contacts>
    </result>
</response>

When I create an XML object through simplexml_load_string() then it will give me most of that XML in the new object, but it won't give me the 'inner' string of FL tags (the CDATA elements), the data that actually interests me.

My new SimpleXML object only has data like:

[1] => SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [val] => Contact Owner
            )

    )

My best guess is that this is because the XML should not really be built this way, I've read somewhere that your cannot have inner content in XML tag if it has attributes and vice versa (is this correct?).

What are my alternatives? Writing a parser myself is not really an option.

Thanks!

도움이 되었습니까?

해결책

To get attributes:

foreach ($value->attributes() as $key => $val){
    // get all attributes
}

To get data:

echo (string) $load->result->Contacts->row->FL[0];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top