cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Brandon
Level II

Get XML Elements

Hi,

 

I am trying to read and XML file with a structure similar to the snippet below. 

 

<Top Element>
   <Element 1>True</Element 1>
   <Element 2>True</Element 2>
   <Element 3>False</Element 3>
</Top Element>

 

I know how to use the Parse XML by calling out the element names but in the document I have there are hundreds of different element names that I don't want to call out specifically in my code.  I understand that you can grab the Attribute info for each of these using the Text() like the following

 

info = "";

Parse XML(xml,
   On Element("Top Element",

      Text( info= info|| Trim( XML Text() ) || " " )

   )

);

 

With the result of info being "True True False" which I could then parse into a list.  But I don't really want to use this code for as I would not be able to easily know what the value of False actual belongs to.  Is there anyway of getting all the Elements of an XML file and then maybe recursively calling the Parse XML function on those elements to get their attribute info?

 

Thanks,

Brandon

 

 

 

3 REPLIES 3
Craige_Hales
Super User

Re: Get XML Elements

1) try the XML wizard. It has several ways to guess the structure of the XML, and a GUI to tailor the guesses. You might not be able to take advantage of the GUI, except to test the guesses.

XML Wizard can be opened via File->Open or from JSL as shown.XML Wizard can be opened via File->Open or from JSL as shown.

If one of the guesses works, you just need to specify the guess option you need.

dt=open(file,guess("wide"),xmlwizard(0));

2) open the file directly into a table...open(file), below, produces this, probably using the huge guess. Needs an XML extension.

dt=open(file);

elementselements

 

3) Or something like this

file=savetextfile("$temp/xxx.xml","<TopElement>
   <Element1>True</Element1>
   <Element2>True</Element2>
   <Element3>False</Element3>
</TopElement>");
show(loadtextfile(file,xmlparse(1)));
// {TopElement(Element1("True"), Element2("True"), Element3("False"))};

the xmlparse converts the xml structure into a JSL expression tree. See the XML Importer Add-In for a way to make a data table from the parsed expression tree. Comment on add-ins.

 

The XML wizard can probably replace the add-in for most cases.

Craige
Brandon
Level II

Re: Get XML Elements

Thanks for the quick response.  Using the XML wizard I was able to get it working.  

gzmorgan0
Super User (Alumni)

Re: Get XML Elements

@Craige_Hales ,

 

Wowee! I missed the xmlwizard in JMP15. Nice feature.  Thank you for the screenshot.