I have XML files that I need to split into multiple files, and I already have a batch file that does this well for single files. I need to edit the batch file to handle a large number of XML files in a single directory. I've attempted several different ways resolve this, but just can't seem to get it working.
As an added bonus, I'd also like to have the output filename contain items from two different lines within each output file, along with inserted text at the beginning and end of each file.
Here's my current batch file:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET /a destadd=0
SET "OrderString=parentName"
SET "found="
FOR /f "delims=" %%a IN (outbound_shipment_20161023.xml) DO (
ECHO("%%a"|FIND "%NRTOrderString%" >NUL
IF NOT ERRORLEVEL 1 (SET found=Y&set/a destadd+=1)
IF DEFINED found >>"Case!destadd!.xml" ECHO %%a
)
GOTO :EOF
An example of the output file after processing with the above:
<Order parentName="ABC-Corp">
<ClientName>ABC</ClientName>
<GroupName>Client</GroupName>
<SiteName>Home</SiteName>
<CaseNumber>634713</CaseNumber>
<ShippingDate>2016-10-20</ShippingDate>
<ShippingMethod>UPS</ShippingMethod>
<TrackingNumber>89273496512349823723423</TrackingNumber>
<OrderDetail>
<ItemShipped>ABC123</ItemShipped>
<Quantity>1</Quantity>
<ClientOrderId>ABCDEF876</ClientOrderId>
</OrderDetail>
Each original XML file contains several of the individual outputs shown above, that are then separated using the batch file.
The batch file above outputs files with names Case1.xml, Case2.xml, etc. I'd like that to change to be "Case_CaseNumber_ClientOrderID.xml". In addition it would need to have "Shipment" inserted on new lines at the beginning and end of each output file.
Thanks for any help.