我不知道我做錯了什麼,但我只是無法正確加載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