0

这些天,我在做一些与解析xml文件相关的工作,在研究了XSLT和XMLParser之后,我决定采用SimpleXMLElement,因为它的灵活性和对XPath的支持。

但是如果 xml 文件中出现某些属性(例如 'xmlns'),SimpleXMLElement::xpath 就不能正常工作,如下所示:

<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1" http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd"
    identifier="choice" title="Item 11 (single choice)" adaptive="false" timeDependent="false">

所以我想用 xml 文件中的这样的字符串替换

<assessmentItem>

在我实例化任何 SimpleXMLElement 对象之前。

对于熟悉正则表达式的人来说,这可能很容易,但我们将不胜感激。

这是关于 SimpleXMLElement::xpath 的文档: http ://www.php.net/manual/en/simplexmlelement.xpath.php

4

0 回答 0