如何为以下模式编写正则表达式?

时间:2013-08-13 07:00:48

标签: php regex preg-replace

现在,我正在做一些与解析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

0 个答案:

没有答案
相关问题