dourenzhou8740 2013-03-22 07:28
浏览 43

PHP - 如何从包含XML结构的变量中删除一些特定元素?

I have one field $xml that contains some XML value. First I must mention that elements are not seperated each in new line (row) but they are bounded together like a String without new lines.

I will first display XML structure how it looks to be easily "readable".

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv=" http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <p:queryBillingAccountResponse xmlns:p=" http://www.ibm.com">
            <ns0:customerAccount xmlns:ns0=" http://www.ibm.com/xmlns/">
                <AccountStatus>Paid</AccountStatus>
                <ComponentCustomerAccount>
                    <Name>ADSL 4</Name>
                    <CharacteristicValue>
                        <Characteristic>
                            <Name>Balance</Name>
                        </Characteristic>
                        <Value>0.0</Value>
                    </CharacteristicValue>
                    <AccountStatus>Paid</AccountStatus>
                </ComponentCustomerAccount>
            </ns0:customerAccount>
        </p:queryBillingAccountResponse>
    </soapenv:Body>
</soapenv:Envelope>
<AccountStatus>Paid</AccountStatus>
</ComponentCustomerAccount>
</ns0:customerAccount>
</p:queryBillingAccountResponse>
</soapenv:Body>
</soapenv:Envelope>

but I again I must mention that real value in $xml field is not so easily readable. On example it looks like this

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv=" http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><p:queryBillingAccountResponse xmlns:p=" http://www.ibm.com">.......

I want to delete elements : ?xmlversion soapenv:Envelope and soapenv:Body along with their attributes. I want to delete them on the beggining and on the end of xml value. Everything else stays as it is1 How to achive this? So my new value in php field should start from queryBillingAccountResponse element. thank you

  • 写回答

3条回答 默认 最新

  • doutang3815 2013-03-22 08:04
    关注

    You can use ereg_replace http://php.net/manual/en/function.ereg-replace.php

    Using regex to identify elements you want to delete.

    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)