Need some help with a batch file

Soldato
Joined
7 Aug 2003
Posts
8,030
Location
Bedfordshire
Hi All,

I've got to add 200 new items to an xml file.

My programming skills are rather weak as I haven't done any for ages, here is the format of the document:

<Product UnitID="0035-1889" Version="V5.1">
<Group Name="StandardFlags"/>
<Group Name="StandardPlots"/>
<Group Name="Channel1"/>
</Product>

I want to be able to feed this file in to the batch program, increment the 'UnitID number' by 1 for a maximum of 200 times and then either write to the same document or write to a new one.

All help greatly appreciated.
 
Associate
Joined
7 Aug 2011
Posts
726
Location
Planet Earth
where are you getting these 200 items from?

yeah what you have said is possible, use PHP/.NET/Python etc to create a script, that takes each item, adds a unitID and creates the required XML.
 
Associate
Joined
24 Jul 2013
Posts
17
Location
Gloucestershire
Here's a PHP script that will do it and save to output.xml in the same directory:

Code:
<?php

	$start = 1889;
	$finish = $start + 200;

	$xmlString = '';

	for($i = $start; $i < $finish; $i++) {

		$xmlString .= '<Product UnitID="0035-' . $i . '" Version="V5.1">
<Group Name="StandardFlags"/>
<Group Name="StandardPlots"/>
<Group Name="Channel1"/>
</Product>';

	}

	file_put_contents('output.xml', $xmlString);

?>

To run it, just save as something like test.php and go to the command line and type: php test.php
(You'll need the php directory added to your Path environment variable if you're running Windows)
 
Last edited:
Back
Top Bottom