i want to split 1 XML file on multiple smaller one, always from tag . As soon PHP is the only language i know a bit i decide to use it.
My try looks like:
$xnl_file = "xml.xml";
$xml = simplexml_load_file($xnl_file);
$my_file = 0;
foreach ($xml as $value){
$CountryOrganizationId = "<CountryOrganizationId>".$xml->Partnership->CountryOrganizationId."</CountryOrganizationId>";
$PartnershipId = "<PartnershipId>".$xml->Partnership->PartnershipId."</PartnershipId>";
$OwnerId = "<OwnerId>".$xml->Partnership->OwnerId."<OwnerId>";
$PartnerIdList = "<PartnerIdList><String>".$xml->Partnership->PartnerIdList->String."</String></PartnerIdList>";
$CountryOrganizationId_contact = "<Contract><CountryOrganizationId>".$xml->Partnership->Contract->CountryOrganizationId."</CountryOrganizationId>";
$ContractId = "<ContractId>".$xml->Partnership->Contract->CountryOrganizationId."</ContractId>";
$Role = "<LaborRateList><LaborRateDetail><Role>".$xml->Partnership->LaborRateList->LaborRateDetail->Role."</Role>";
$Category = "<Category>".$xml->Partnership->LaborRateList->LaborRateDetail->Category."</Category>";
$Rate1 = "<Rate Cur='CZK' Unit='h' MinValue='0' MaxValue='0'>".$xml->Partnership->LaborRateList->LaborRateDetail->Rate."</Rate></LaborRateDetail>";
echo $OwnerId;
echo "<br>";
$my_file = ($my_file + 1).".xml";
//mkdir("new", 0700); Create subfolder
$handle = fopen('xml/'.$my_file, 'w') or die('Cannot open file: '.$my_file); //implicitly creates files in XML folder
$data = "<Partnership>".$CountryOrganizationId.$PartnershipId.$OwnerId.$PartnerIdList.$CountryOrganizationId_contact.$ContractId.$Role.$Category.$Rate1."</Partnership>";
fwrite($handle, $data);
}
As you can see i just load XML file and foreach getting values and adding them to variabiles and then trying to print again. isn't there some faster way just to CUT when find a tag Partnership?
My XML looks like:
<PartnershipList xmlns="URL">
<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>
Thanks for any advise