Choose Language Hide Translation Bar
Using the JSL XML parser to import KML map shapes

XML (Extensible Markup Language) format is widely used on the internet, and XML-based languages have become the default for many  tools, such as Microsoft Office, OpenOffice, iWork, and Google Earth. So it is not surprising when JMP users come across some XML-based data that looks like this:

JSL has a function called "Parse XML" to make importing XML data easier. In the above XML example, ONSALE is a start tag, and /ONSALE is an end tag. There are two pairs of ITEM tags within ONSALE, each containing a pair of NAME tags and PRICE tags. Using "Parse XML," you can look for certain tags and take action. Furthermore, you can tie the timing of the action to either the start tag or the end tag, or both. The JSL below uses "Parse XML" to get the useful information from the XML sample.

xml_file = load text file("onsaleItems.xml");

Parse XML(




Start Tag(print("The following items are on sale")),


On Element(


End Tag(

message = item_name || " for " || item_price || " a pound.";




On Element(


End Tag(item_name = XML Text(); ),


On Element(


End Tag(item_price = XML Text(); ),




"The following items are on sale"

"Banana for 0.59 a pound."

"Tomato for 1.19 a pound."

The book JSL Companion: Application of the JMP Scripting Language has an in-depth section about XML parsing and importing XML data into JMP table. One of the authors, Theresa Utlaut, shared "Sample Code and Data," including several scripts about XML parsing on her SAS Press author Web page.

I have recently used the XML parser for a mapping-related add-in, the KML Polygon Importer, which you can download from the JMP File Exchange (download requires free SAS profile). KML stands for Keyhole Markup Language. It became an international standard of the Open Geospatial Consortium, and it is becoming increasingly popular as a mapping tool. Because KML is XML-based, I was able to use the XML parser to import the KML maps into JMP data tables, which then can be displayed as JMP maps. Here is a KML model of Bloomington, Indiana, being displayed in JMP. Each shape is a building viewed from above and is shaded according to its average altitude.


Article Labels

    There are no labels assigned to this post.

Article Tags

Cristian Ureña Hdz wrote:

Hi, how can I parse the attributes "name" and "station" into the columns L1 and L2 I created in the code? I got to parse "string" and "oncomplete" tags... but no the attributes.

See portion of XML file and JSL code.

XML portion:

processcontentproductrebootPRETEST FLASH

JSL code:

Parse XML( file_contents,


Start Tag(

dt = New Table( "ProcessMap",

New Column( "L1", character ),

New Column( "L2", character ),

New Column( "L3", character ),

New Column( "Script", character ),

); //end New Table

row=1;)), //end Start Tag, processcontrol OnElement

OnElement("state",Start Tag(if(row>0, dt << Add Rows( 1 ));),End Tag(row++;)),

//OnElement("state",Start Tag( if(row>0, dt << Add Rows( 1 ),column(dt,"L2")[Row()]= Parse(XML Attr( "name")))),End Tag(row++;)),

//OnElement("station", End Tag(column(dt,"L1")[Row()] = XMLDecode(XML text()))),

//OnElement("state", Start Tag(column(dt,"L2")[Row()]= XML Attr( "name" ))),

//OnElement("name", End Tag(column(dt,"L2")[Row()]= XML text())),

OnElement("oncomplete", End Tag(column(dt,"L3")[Row()] = XML Decode(XML text()))),

OnElement("script", End Tag(column(dt,"Script")[Row()] = XML text()))



Xan Gregg wrote:

Your XML did not survive the blog comment system. Looks like you're close, though. You might go back to the XML Attr() example in Help > Scripting Index and modify to one step at a time to get to your application. If that doesn't help, try the JMP community discussion forum, which can accommodate embedded code better.