Reconstruction of the parsing of XML data
1. The XML data is printed as follows. as shown in Figure 1
1626662709
2. At this stage, the XML is converted into an array. The code is implemented as follows. The libxml_disable_entity_loader function has been abandoned since PHP 8.0.0. It is strongly recommended not to rely on this function.
libxml_disable_entity_loader(true);
$values = Json::decode(Json::encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
3. After converting to an array, the printing result is as follows. as shown in Figure 2
Array
(
[AppId] => wxd98c58b273d21bdf
[CreateTime] => 1626662709
[InfoType] => component_verify_ticket
[ComponentVerifyTicket] => ticket@@@bVAZ8WK0CCTWNowBEfvH7SWIRiPhoeNVczaOnAiPN8fzN2tNrxNK_mzJaUd-WFslGAyl6cSR1ryUinlthRQ0SA
)
4. Delete function: libxml_disable_entity_loader. not converted to arrays. Use objects directly. libxml_nocdata means to merge cdata into text nodes. as shown in Figure 3
$values = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
print_r($values);
echo $values->AppId;
exit;
SimpleXMLElement Object
(
[AppId] => wxd98c58b273d21bdf
[CreateTime] => 1626662709
[InfoType] => component_verify_ticket
[ComponentVerifyTicket] => ticket@@@bVAZ8WK0CCTWNowBEfvH7SWIRiPhoeNVczaOnAiPN8fzN2tNrxNK_mzJaUd-WFslGAyl6cSR1ryUinlthRQ0SA
)
wxd98c58b273d21bdf


