PHP - how to parse STRING field (remove some XML elements and all namespaces)?

immasiaoblila

New Member
I really need a help about string parsing in field containg not valid XML value.I will display current value with target value to put in string field.I have a field $xmlString with this value (elements are NOT in the SEPERATE lines but in the SAME line; it is web service response so I do not have impact on response only on later parsing):\[code\]<?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>\[/code\]I want this output if this is possible:\[code\]<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>\[/code\]So you will notice that I do not have first three lines (although they are not really seperate lines) and last two lines and I do not have namespaces defined for \[code\]queryBilling AccountResponse\[/code\] and \[code\]customer Account\[/code\]. I want these elements without namespace to be in string field. For both on start and end tag. I really need this output. How to parse this? I tried with SimpleXMLElement but could not parse it.Thank you for your helpUpdated output which can not be parsed by $xml = simplexml_load_string($text);\[code\]<<<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>\[/code\]
 
Back
Top