Using Pan X to Create an xml File?

I have a 5 column database with 185 records that I would like to use to create an xml file using the following xml schema:

<INVENTORY>
	<ITEM>
		<ITEMTYPE>P</ITEMTYPE>
		<ITEMID>30377</ITEMID>
		<COLOR>11</COLOR>
		<MINQTY>8</MINQTY>
		<CONDITION>N</CONDITION>
	</ITEM>
	<ITEM>
		<ITEMTYPE>P</ITEMTYPE>
		<ITEMID>30374</ITEMID>
		<COLOR>11</COLOR>
		<MINQTY>2</MINQTY>
		<CONDITION>N</CONDITION>
	</ITEM>
</INVENTORY>

Is there a way to generate this type of file? Any help would be greatly appreciated. Thanks.

Local thePage
thePage = "<INVENTORY>"+lf()+arraybuild(lf(),"",
{"	<ITEM>"+lf()+
"		<ITEMTYPE>"+ItemType+"</ITEMTYPE>"+lf()+
"		<ITEMID>"+ItemID+"</ITEMID>"+lf()+
"		<COLOR>"+Color+"</COLOR>"+lf()+
"		<MINQTY>"+MinQTY+"</MINQTY>"+lf()+
"		<CONDITION>"+Condition+"</CONDITION>"+lf()+
"	</ITEM>"})+lf()+
"</INVENTORY>"

filesave "~/Desktop/Inventory.xml", thePage
1 Like

Hi Dave,

Thanks for your reply. I’m assuming I just need to copy that code into a procedure and the run it. Is that correct?

It is if I guessed the field names correctly. They are case sensitive, so it’s likely that you will need to change some lower case letters to upper case or vice versa, at the very least.

You were close. Those are the field names but they are in all caps. Easy fix. Thanks for the help.

I just edited my code. I had left off the angle brackets around \ITEMTYPE. And that should have been a slash, rather than a backslash.

I caught that and corrected it too. Thanks.

For some background, I’m an avid LEGO designer/builder. This procedure allowed me to convert my parts list into the xml format needed to upload to a “Wanted List” on the Bricklink website. Bricklink is a worldwide market place for purchasing LEGO parts. Again thanks for your help. Regards, John

A suggestion for the future - this procedure could be created with less typing by using the xtag( function. This would eliminate the need to type each tag name twice, and also eliminate the need to type the /. So less chance for errors.

So for example:

"		<COLOR>"+Color+"</COLOR>"+lf()+

could be written as:

"		"+xtag("COLOR",Color)+lf()+

A minor change, but slightly easier. I wouldn’t change the working code you already have though.

Thanks Jim. I’ll keep that in mind, but the procedure Dave sent worked perfectly. I was able to upload over 100 items in just seconds.

As I said, I wouldn’t bother changing the working code you already have. I added my suggestion for the benefit of future readers who may come across this topic months or years from now.

Hi Dave. If possible, how would I modify the code to allow me to select the save location and name of the resulting xml file?

Check out the SaveDialog statement.

You would place this statement ahead of the filesave statement, and you would use the variable you used to capture the path as the first parameter in the filesave.

Thanks. I give it a try.