我收到一个来自api的响应,该xml是xml,但格式看起来不正确,我该如何格式化它并获取每个元素。
我尝试使用simplexml_load_string()
,但是它保存了数据并删除了<xml>
开头标签。以下是我从api获得的响应。
<?xml version="1.0" encoding="utf-8"?><string xmlns="http://hts.org/"><Info><Status>1</Status><ChasisNo>dfrtdf4543</ChasisNo><Color>Black</Color><PolicyNo>POL\CR\2014\0000</PolicyNo><Model>Hiace</Model><Name>Tawakalitu</Name><NewRegistrationNo>HB90IKJ</NewRegistrationNo><RegistrationNo>HB90IKJ</RegistrationNo><Model>Hiace</Model><CarMake>Toyota</CarMake><VehicleType>hatchback</VehicleType><IssueDate>31 DECEMBER 2015</IssueDate><ExpirationDate>30 DECEMBER 2050</ExpirationDate><Dateuploaded>29 DECEMBER 2011</Dateuploaded><Timeuploaded> 1:51AM</Timeuploaded></Info></string>
有了simplexml_load_string
,我得到了类似下面的内容而没有xml标记,我想获取每个元素而不是将其作为一个整体字符串
<InsuranceInfo><Status>1</Status><ChasisNo>dfrtdf4543</ChasisNo><Color>Black</Color><PolicyNo>POL\CR\2019\0000</PolicyNo><Model>Hiace</Model><Name>Tawakalitu</Name><NewRegistrationNo>HB90IKJ</NewRegistrationNo><RegistrationNo>HB90IKJ</RegistrationNo><Model>Hiace</Model><CarMake>Toyota</CarMake><VehicleType>hatchback</VehicleType><IssueDate>31 DECEMBER 2019</IssueDate><ExpirationDate>30 DECEMBER 2020</ExpirationDate><Dateuploaded>29 DECEMBER 2019</Dateuploaded><Timeuploaded> 1:51AM</Timeuploaded></InsuranceInfo>