从 xml 字符串中删除属性


Remove attributes from xml string

<soap-env:envelope xmlns:soap-enc="" xmlns:soap-env="">
    <soap-env:header>
    </soap-env:header>
    <soap-env:body>
        <ns1:createuserresponse>
            <username>weqew_825</username>
            <password>uwnoqedcjs</password>
            <result>
                <succeeded>true</succeeded>
                <errorcode>0</errorcode>
                <errortext></errortext>
            </result>
        </ns1:createuserresponse>
    </soap-env:body>
</soap-env:envelope>

我想从上面的字符串中删除xmlns:soap-enc="" xmlns:soap-env=""

您可以使用preg_replace

$string = preg_replace('/xmlns:.*'"/','',$string);

但最好避免这种情况,因为再次使用 SimpleXML 解析该 xml 将生成大量警告(可以用 @ 来填充(。

更可靠的解决方案

  • 使用单面 XML 解析具有命名空间的 XML
  • PHP:如何处理 SOAP 响应来获取标签值?

希望它有帮助