Question

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!

Was it helpful?

Solution

To get attributes:

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

To get data:

echo (string) $load->result->Contacts->row->FL[0];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top