Hello - I'm trying to import a few hundred XML files. These files need to come in as a single row, and some lines need to be split into multiple columns, so as far as I can tell, the XML import wizard is out. I tried using the code from the import wizard as a starting point but A) I couldn't see how to easily put in a lot of nuance (like specifying splitting of text into columns, with one column being up to a 35k entry csv formatted string) and B) I didn't find a lot of documentation on XML Settings. I did find both documentation and community support on Parse XML. However, I've been working for quite a while to adapt code I found on the forums and in the scripting index (and maybe even some rather unhelpful queries to ChatGPT) to no avail. I'm very much a noobie to jsl (and coding in general), so this might be very simple.
This is what I got right now. I had more, but I guess to start, I just want to be able to access the xml data and use the Parse command correctly, but I'm having serious trouble getting anything but a table created, and I don't seem to be grabbing the attribute correctly, as the table shows up unnamed:
// Specify your preferred default folder
default_folder = "G:\My Drive\Edward H Chandler, Jr\VCU - Research\CERCAS\Project 46\XRD";
Set Default Directory( default_folder );
// Use the default folder to pick a file
file contents = Load Text File( Pick File(default_folder) );
Parse XML( file contents,
On Element(
"http://www.xrdml.com/XRDMeasurement/2.1^sample",
StartTag(
sheetname = XML Attr(
"http://www.xrdml.com/XRDMeasurement/2.1^type"
);
dt = New Table( sheetname );
row = 1;
col = 1;
)
)
);
I'm pulling largely from here and here, but I'm noticing some undocumented syntax, like the inclusion of a second term in the XML Attr command with "Untitled" in that first link, so I'm not even sure if this code is generally applicable, though I did get it to work on the BigData file it was made for. I also am unsure about the use of the "^" to indicate children, but I'm kinda lost at this point. I suppose it could also be an issue with the namespace being titled as a webpage, but my understanding is a string is a string is a string.
Anyway, does anyone have any suggestions or comments? I'm even open to switching back to the XML settings route.
I've also attached one of the xml files. It was originally an .xrdml file, but my understanding is that that is structured as an xml file, so I just changed the filetype.
Thanks in advance!
Edward Hamer Chandler, Jr.