Page 1 of 1

Breaking up an XML

Posted: Mon Nov 25, 2013 7:59 pm
by sgeller
Our usual flows are one XML and a PDF that were able to use XML Pickup with.



We now have a client suppling our order info as a single XML that refers to several PDFs.



Is there a way to have switch pluck out the multiple orders and write the separate XML files where the PDFs will be waiting?



<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<Order>

<OrderID>434590</OrderID>

<OrderDate>2013-11-20T20:25:58.577</OrderDate>

<OrderEmail>test@here.com</OrderEmail>

<OrderItem>

<OrderItemID>895</OrderItemID>

<ProductID>3149</ProductID>

<ProductName>Card</ProductName>

<LocationID></LocationID>

<LocationDesc></LocationDesc>

<FileName>20131120_202530.pdf</FileName>

<Recipient>

<Qty>50</Qty>

<ShipFirstName></ShipFirstName>

<ShipLastName></ShipLastName>

<ShipAddress1></ShipAddress1>

<ShipAddress2></ShipAddress2>

<ShipCity></ShipCity>

<ShipState></ShipState>

<ShipZip></ShipZip>

<ShipPhone></ShipPhone>

<ShipEmail></ShipEmail>

</Recipient>

</OrderItem>

<OrderItem>

<OrderItemID>1825</OrderItemID>

<ProductID>3150</ProductID>

<ProductName>Poster</ProductName>

<LocationID>6</LocationID>

<LocationDesc></LocationDesc>

<FileName>20131120_206630.pdf</FileName>

<Recipient>

<Qty>10</Qty>

<ShipFirstName></ShipFirstName>

<ShipLastName></ShipLastName>

<ShipAddress1></ShipAddress1>

<ShipAddress2></ShipAddress2>

<ShipCity></ShipCity>

<ShipState></ShipState>

<ShipZip></ShipZip>

<ShipPhone></ShipPhone>

<ShipEmail></ShipEmail>

</Recipient>

</OrderItem>

</Order>



So we'd like to write out in each new file

<OrderID>434590</OrderID>

<OrderDate>2013-11-20T20:25:58.577</OrderDate>

<OrderEmail>test@here.com</OrderEmail>

and then one each of <OrderItem>

saving the XML as the corresponding PDF in <FileName>



Is this possible? Or is there a secret feature of switch that makes this simple?

Breaking up an XML

Posted: Mon Nov 25, 2013 9:04 pm
by dkelly
There's no built-in method for doing what you have described. You can use either XSL transform or a relatively simple Javascript.

Breaking up an XML

Posted: Tue Nov 26, 2013 2:53 pm
by freddyp
How are the files supplied? If you get everything in a folder with an XML that has the same name as the folder, and the names of the PDF files in that folder are exactly the same as the ones in the XML, then you can get to the metadata for each PDF using a somewhat advanced XPath expression.



If not and the XML really needs splitting up, you can do that using XSL2.0. The current version of Switch only supports XSL1.0. You can install an XSL2.0 processor like Saxon (http://saxon.sourceforge.net/) and run it from an Execute command element. You will also need an XSL script to transform the 1 XML into n XML files. Very much doable, but it takes too much time to elaborate that here on the forum.



The same is true for a script as Dwight suggests. Very much doable, but not within a reasonable amount of time one can attribute to a forum contribution.



Get back with more info on the job structure and if it requires a script (JS or XSL) then I suggest that you contact your reseller to see if he/she provides a service to do that for you.



Freddy