我真的需要关于字段中包含无效 XML 值的字符串解析的帮助。我将显示当前值和目标值以放入字符串字段。
我有一个具有此值的字段 $xmlString (元素不在单独的行中,而是在同一行中;它是 Web 服务响应,因此我仅在以后的解析中对响应没有影响):
<?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/2009">
<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>
如果可能的话,我想要这个输出:
<queryBillingAccountResponse>
<customerAccount>
<ComponentCustomerAccount>
<Name>ADSL 4</Name>
<CharacteristicValue>
<Characteristic>
<Name>Balance</Name>
</Characteristic>
<Value>0.0</Value>
</CharacteristicValue>
<CharacteristicValue>
<AccountStatus>Paid</AccountStatus>
</ComponentCustomerAccount>
</customerAccount>
</queryBillingAccountResponse>
所以你会注意到我没有前三行(尽管它们不是真正单独的行)和最后两行,而且我没有为queryBilling AccountResponse
and定义命名空间customer Account
。我希望这些没有命名空间的元素位于字符串字段中。对于开始和结束标签。我真的需要这个输出。如何解析这个?我尝试使用 SimpleXMLElement 但无法解析它。谢谢您的帮助
更新了 $xml = simplexml_load_string($text); 无法解析的输出
<<<XML
<?xml version="1.0" encoding="utf-8"?>
<Envelope>
<Body>
<queryBillingAccountResponse>
<customerAccount>
<ComponentCustomerAccount>
<Name>ADSL 4</Name>
<CharacteristicValue>
<Characteristic>
<Name>Balance</Name>
</Characteristic>
<Value>0.0</Value>
</CharacteristicValue>
<AccountStatus>Paid</AccountStatus>
</ComponentCustomerAccount>
</customerAccount>
</queryBillingAccountResponse>
</Body>
</Envelope>
XML>