SimpleXML keeps returning content on CDATA element

后端 未结 2 1978
误落风尘
误落风尘 2021-01-26 10:15

So another CDATA returning content question. I\'ve seen many answers, but even though I tried them all, I still get only content.

In more details:

I have an xml

相关标签:
2条回答
  • 2021-01-26 10:29

    I think your example returns 'content' because you are concatenating an element that does not exist

    $element->NewsComponent->ContentItem->DataContent->body->body
    

    with the string 'content' - probably PHP complains that there's no constant with the name content and therefore assumes you meant 'content'.

    Thus my guess is you need to find another way to select an element with a dot in the name.

    (This problem does not appear to be related to CDATA.)

    0 讨论(0)
  • 2021-01-26 10:40

    For element names which cannot be PHP identifiers (like body.content), you must use an alternative PHP notation:

    $element->NewsComponent->ContentItem->DataContent->body->{'body.content'};
    
    0 讨论(0)
提交回复
热议问题