首页 > 解决方案 > 解析具有 HTML 值的 XML 数据

问题描述

你好,

我有一个返回 XML 数据但以 HTMl 作为内容的端点,

到目前为止,使用simplexml_load_string($result, "SimpleXMLElement", LIBXML_NOCDATA);返回一个条纹版本,即所有标签都被删除

样本数据

<JUDGMENT>
    <summary>INTRODUCTION: <br />This appeal borders on the Law of Contract.<br /><br />FACTS: <br />From the statement of claim filed by the plaintiff (respondent) breach of contract and negligence were said to have been committed against it, by the appellant. Amongst other prayers, the respondent claimed:-<br />(a) one hundred million naira as general damages for malicious breach of contract and negligent conduct;<br />(b) sixty-four million, two hundred and fifty thousand, nine hundred and twenty naira as special damages;<br /></summary>
</JUDGMENT>

通过我的方法解析

protected function scaffoldXML($result)
    {
        $xml = simplexml_load_string($result, "SimpleXMLElement", LIBXML_NOCDATA);
        return $json = json_encode($xml);
    }

退货

"summary":"INTRODUCTION: This appeal borders on the Law of Contract.FACTS: From the statement of claim filed by the plaintiff (respondent) breach of contract and negligence were said to have been committed against it, by the appellant. Amongst other prayers, the respondent claimed:-(a) one hundred million naira as general damages for malicious breach of contract and negligent conduct;(b) sixty-four million, two hundred and fifty thousand, nine hundred and twenty naira as special damages;(c) one million, five hundred thousand naira only being the cost of this action; and(d) 10% interest per annum on the judgment sum, from the date of judgment until liquidation.The appellant denied the claim and on exchange of pleadings...

再次提问

我想在删除 XML 标签的同时保留数据中的 HTML 标签

请注意 这是一个完整的 XML,其结构无法预测,我想提取 XML 中的所有值,而不仅仅是部分

标签: phpjsonxmlsimplexml

解决方案


推荐阅读