My first post here. I have searched but haven’t found what I’m looking for.
I am not really sure what technique I need to do the following.
I use Mule 3.3 CE and I need to split XML files. I need to keep the “rootElement” and its attributes in each and every splitted XML. All XML-files will be dropped in the same JMS Queue.
I know how to split the three Product-nodes but how can I keep the “rootElement” on each an every XML-file?
XPath? XSLT? DOM and remove and add nodes?
I would prefer just an XPath but does it have the strength to do this?
<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
preOrderTo="2012-12-31T23:59:59"
currency="GBP"
timeStamp="2012-08-15T23:59:59">
<Product
itemID="09999-3-"
name="Plate"
description="Plate of blue man"
tax="0.00"
eanCode="1234567890123"
eanType="EAN 13"/>
<priceBracket quantity="1"
price="10.98"
grossPrice="13.00"/>
<Product
itemID="12345-3-"
name="Plate"
description="Plate of black man"
tax="0.00"
eanCode="1234569870123"
eanType="EAN 13"/>
<priceBracket quantity="1"
price="15.98"
grossPrice="18.00"/>
<Product
itemID="98765-3-"
name="Plate"
description="Plate of yellow man"
tax="0.00"
eanCode="7894567890123"
eanType="EAN 13"/>
<priceBracket quantity="1"
price="20.98"
grossPrice="24.00"/>
</rootElement>
What I need in Mule 3.3 CE is the following split:
1.
<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
preOrderTo="2012-12-31T23:59:59"
currency="GBP"
timeStamp="2012-08-15T23:59:59">
<Product
itemID="09999-3-"
name="Plate"
description="Plate of blue man"
tax="0.00"
eanCode="1234567890123"
eanType="EAN 13"/>
<priceBracket quantity="1"
price="10.98"
grossPrice="13.00"/>
</rootElement>
2.
<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
preOrderTo="2012-12-31T23:59:59"
currency="GBP"
timeStamp="2012-08-15T23:59:59">
<Product
itemID="12345-3-"
name="Plate"
description="Plate of black man"
tax="0.00"
eanCode="1234569870123"
eanType="EAN 13"/>
<priceBracket quantity="1"
price="15.98"
grossPrice="18.00"/>
</rootElement>
3.
<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
preOrderTo="2012-12-31T23:59:59"
currency="GBP"
timeStamp="2012-08-15T23:59:59">
<Product
itemID="98765-3-"
name="Plate"
description="Plate of yellow man"
tax="0.00"
eanCode="7894567890123"
eanType="EAN 13"/>
<priceBracket quantity="1"
price="20.98"
grossPrice="24.00"/>
</rootElement>
If you can use XSLT 2.0, here’s one way…
XML Input
XSLT 2.0
Resulting XML files (name based on itemID of Product, but could be changed easily)…
09999-3-.xml
12345-3-.xml
98765-3-.xml