我不知道我做错了什么,但我只是无法正确加载XML与我的PHP。 我尝试使用加载文档和simplexml_load_file等,但我总是收到错误。XML加载文件与PHP
示例代码我尝试:
$xnl_file = "xml.xml";
$xml = simplexml_load_file($xnl_file);
var_dump($xml);
的错误,我得到:
Warning: simplexml_load_file(): xml.xml:3: parser error : Extra content at the end of the document in C:\xampp\htdocs\xampp\provisioning\index.php on line 3
Warning: simplexml_load_file(): <PartnershipList xmlns="http://www.audatex.com/SAXIF"> in C:\xampp\htdocs\xampp\provisioning\index.php on line 3
Warning: simplexml_load_file():^in C:\xampp\htdocs\xampp\provisioning\index.php on line 3
bool(false)
XML的样子:
<?xml version="1.0" encoding="UTF-8"?>
<CreationDateTime>Wed Nov 05 12:30:38 CET 2014</CreationDateTime>
<PartnershipList xmlns="http://www.audatex.com/SAXIF">
<Partnership>
<CountryOrganizationId>CZ</CountryOrganizationId>
<PartnershipId>Contract_58AB4635-D9C6-A04E</PartnershipId>
<OwnerId>MM-O-BDD15299</OwnerId>
<PartnerIdList>
<String>MM-O-2A10BCF</String>
</PartnerIdList>
<Contract>
<CountryOrganizationId>CZ</CountryOrganizationId>
<ContractId>Contract_58AB4635-D9C6-A04E</ContractId>
<LaborRateList>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Paint</Role>
<Category>2</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">350.0</Rate>
</LaborRateDetail>
</LaborRateList>
<IdBlockCodeList>
<IDBlockCode>
<IDBlockCode>51</IDBlockCode>
<Entry>100</Entry>
</IDBlockCode>
</IdBlockCodeList>
<VehicleKind>Car</VehicleKind>
<RepairKind>BodyRepair</RepairKind>
<ManufacturerCode>07</ManufacturerCode>
<Status>Active</Status>
<CreatedBy>MM-P-69F997009BBFB4FC2C</CreatedBy>
<CreationTimeStamp>2014-09-09T15:17:46.000</CreationTimeStamp>
<UpdatedBy>MM-P-69F997009BBFB4FC2C</UpdatedBy>
<UpdateTimeStamp>2014-10-15T10:49:18.000</UpdateTimeStamp>
<FirstVersionContractId>Contract_58AB4635-D9C6-A04E</FirstVersionContractId>
<OwnerId>MM-O-BDD15299</OwnerId>
<Manufacturer>07</Manufacturer>
<VehicleType>Car</VehicleType>
<VehicleAgeFrom>0</VehicleAgeFrom>
<VehicleAgeTo>0</VehicleAgeTo>
<ClaimType>Unknown</ClaimType>
</Contract>
<Description>Alfa Romeo</Description>
<PartnerId>MM-O-2A10BCF</PartnerId>
</Partnership>
<Partnership>
<CountryOrganizationId>CZ</CountryOrganizationId>
<PartnershipId>Contract_F5134A37-F39A-823A</PartnershipId>
<OwnerId>MM-O-BDD15299</OwnerId>
<PartnerIdList>
<String>MM-O-2A10BCF</String>
</PartnerIdList>
<Contract>
<CountryOrganizationId>CZ</CountryOrganizationId>
<ContractId>Contract_F5134A37-F39A-823A</ContractId>
<LaborRateList>
<LaborRateDetail>
<Role>Labor</Role>
<Category>1</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">250.0</Rate>
</LaborRateDetail>
<LaborRateDetail>
<Role>Paint</Role>
<Category>2</Category>
<Rate Cur="CZK" Unit="h" MinValue="0" MaxValue="0">350.0</Rate>
</LaborRateDetail>
</LaborRateList>
<IdBlockCodeList>
<IDBlockCode>
<IDBlockCode>51</IDBlockCode>
<Entry>100</Entry>
</IDBlockCode>
</IdBlockCodeList>
<VehicleKind>Car</VehicleKind>
<RepairKind>BodyRepair</RepairKind>
<ManufacturerCode>10</ManufacturerCode>
<Status>Active</Status>
<CreatedBy>MM-P-69F997009BBFB4FC2C</CreatedBy>
<CreationTimeStamp>2014-09-09T15:22:27.000</CreationTimeStamp>
<UpdatedBy>MM-P-69F997009BBFB4FC2C</UpdatedBy>
<UpdateTimeStamp>2014-10-15T13:11:36.000</UpdateTimeStamp>
<FirstVersionContractId>Contract_F5134A37-F39A-823A</FirstVersionContractId>
<OwnerId>MM-O-BDD15299</OwnerId>
<Manufacturer>10</Manufacturer>
<VehicleType>Car</VehicleType>
<VehicleAgeFrom>0</VehicleAgeFrom>
<VehicleAgeTo>0</VehicleAgeTo>
<ClaimType>Unknown</ClaimType>
</Contract>
<Description>Citroën</Description>
<PartnerId>MM-O-2A10BCF</PartnerId>
</Partnership>
我谷歌很多的教程,但看起来我做错了什么刚刚开始。有人可以给我任何建议吗?
谢谢
错误消息是说你的XML文档是无效的。所以修复你的XML文档。 – TRiG 2014-11-05 12:13:32
你需要得到正确的XML,它缺少一个父节点,并在PartnershipList – Ghost 2014-11-05 12:17:14