Я немного новичок здесь в stackoverflow, так что простите меня заранее.:)
Я пытаюсь объединить объекты с одним и тем же BranchCode и, по сути, просто превращаю ветвь в дочерний узел основного узла Product.Пожалуйста, посмотрите мой образец XML ниже.Спасибо.
У меня есть этот XML (simpleXMLElement->asXML()
):
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>14</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>150</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>226</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>227</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>26</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>34</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>35</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>400A</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>405A</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>460A</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>57</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>83</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>C3</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-02-2166</ProductCode>
<BranchCode>Global</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>14</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>150</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>226</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>227</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>26</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>34</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>35</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>400A</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>405A</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>460A</BranchCode>
<Available>5.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>57</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>83</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>C3</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>0.00</AvailableGlobally>
</Product>
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-051-2030</ProductCode>
<BranchCode>Global</BranchCode>
<Available>0.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>5.00</AvailableGlobally>
</Product>
</ArrayOfProduct>
И я хочу вывод, похожий на этот:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Product>
<Customer>238500</Customer>
<ProductCode>AAA-50-3535</ProductCode>
<Branch>
<BranchCode>C3</BranchCode>
<Available>10.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>100.00</AvailableGlobally>
</Branch>
<Branch>
<BranchCode>A5</BranchCode>
<Available>20.00</Available>
<AvailableCSL>0.00</AvailableCSL>
<AvailableGlobally>100.00</AvailableGlobally>
</Branch>
....
....
</Product>
....
....
</ArrayOfProduct>