cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
d_barnett
Level IV

Importing Multiple xml files From a Folder Location

I have a folder containing lots of xml files that I would like to open, extract information from, save this new information separately ,  and then close both files. I can do this singularly using the 'Import xml' add-in but would like to go through a complete folder automatically to reduce the amount of effort and time I spend on doing this.

I have attached an example folder with xml files in to help if anyone has the time to do this.

Regards

David

2 ACCEPTED SOLUTIONS

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Importing Multiple xml files From a Folder Location

This addin code is very well organized and all its power and functionality can be accessed by running one "master" function. Hence, here it is quite easy to circumvent the addin's GUI and let it work on your xml-files in a loop.

Below is one way to combine the addin with Ian's loop. Note that you may need to set the path variable, i.e. the path to where the addin is installed on your computer. Also, if expanding this code, avoid using variable names that are already used by the included code from the addin, or you may run into problems (e.g. I could not use i as a loop iterator).

 

 

// Define path variable (may already be defined)
Set Path Variable("ADDIN_HOME", "Path/to/my/Addins");

// Define all the functions of the Addin but skip the GUI
Include("$ADDIN_HOME/com.jmp.matthew.wolfe.xml.importer/xml parser III.jsl") << close window;

dir = Pick Directory("Select the directory containing your files", "$DESKTOP");
fList = Files In Directory(dir);
myInfo = [];

For(filenr = 1, filenr <= N Items(fList), filenr++,
// Use Function from Addin to parse file into a data table
    dt = runParser(dir || "/" || fList[filenr]);
//Extract your information here! (e.g n rows of dt)
    myInfo |/= N Rows(dt);
//Close the data table
    Close(dt, no save);
);

// Did it work? Summarize in a new data table
New Table("my xml files",
    add rows(N Items(fList)),
    New Column("Sample", character, Values(fList)),
    New Column("n rows", numeric, values(myInfo))

);
 

View solution in original post

Phil_Kay
Staff

Re: Importing Multiple xml files From a Folder Location

Just to update for anyone searching on this...

This is now handled with ease in JMP 15 with the XML Import Wizard and Import Multiple Files.

You can use the Import Wizard on a single file to define the XML structure. Then copy the XML settings from the Source script and paste into the Settings in the Import Multiple Files dialog.

View solution in original post

6 REPLIES 6
ian_jmp
Level X

Re: Importing Multiple xml files From a Folder Location

You will need something like this, with 'Open()' instead of 'Print()' of course:

 

 

dir = PickDirectory("Select the directory containing your files", "$DESKTOP");
fList = FilesInDirectory(dir);
for(i=1, i<=NItems(fList), i++,
Print(dir||"/"||fList[i]);

);

 

d_barnett
Level IV

Re: Importing Multiple xml files From a Folder Location

Ian,

thanks for the prompt reply but I cannot get this to work with xml files, do I need to parse these or some other technique to open this type of file?

Regards


David

ian_jmp
Level X

Re: Importing Multiple xml files From a Folder Location

Sorry, I thought the issue was the looping, not the reading in. Yes, you will need to parse the XML to pull out what you want once you have used 'LoadTextFile()' to put the contents into a JSL variable. 'ParseXML()' should help.

stan_koprowski
Community Manager Community Manager

Re: Importing Multiple xml files From a Folder Location

HI David,

Check out the XML addin https://community.jmp.com/docs/DOC-7728.  This in combination with what Ian@JMP​ provided should get you going.

Best,

Stan

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Importing Multiple xml files From a Folder Location

This addin code is very well organized and all its power and functionality can be accessed by running one "master" function. Hence, here it is quite easy to circumvent the addin's GUI and let it work on your xml-files in a loop.

Below is one way to combine the addin with Ian's loop. Note that you may need to set the path variable, i.e. the path to where the addin is installed on your computer. Also, if expanding this code, avoid using variable names that are already used by the included code from the addin, or you may run into problems (e.g. I could not use i as a loop iterator).

 

 

// Define path variable (may already be defined)
Set Path Variable("ADDIN_HOME", "Path/to/my/Addins");

// Define all the functions of the Addin but skip the GUI
Include("$ADDIN_HOME/com.jmp.matthew.wolfe.xml.importer/xml parser III.jsl") << close window;

dir = Pick Directory("Select the directory containing your files", "$DESKTOP");
fList = Files In Directory(dir);
myInfo = [];

For(filenr = 1, filenr <= N Items(fList), filenr++,
// Use Function from Addin to parse file into a data table
    dt = runParser(dir || "/" || fList[filenr]);
//Extract your information here! (e.g n rows of dt)
    myInfo |/= N Rows(dt);
//Close the data table
    Close(dt, no save);
);

// Did it work? Summarize in a new data table
New Table("my xml files",
    add rows(N Items(fList)),
    New Column("Sample", character, Values(fList)),
    New Column("n rows", numeric, values(myInfo))

);
 
Phil_Kay
Staff

Re: Importing Multiple xml files From a Folder Location

Just to update for anyone searching on this...

This is now handled with ease in JMP 15 with the XML Import Wizard and Import Multiple Files.

You can use the Import Wizard on a single file to define the XML structure. Then copy the XML settings from the Source script and paste into the Settings in the Import Multiple Files dialog.