parseXML

Parse and return an XML document using the org.w3c.dom.Document API. The XML document to parse can be provided in the following ways:

·         Piece of well-formatted XML

·         URL relative to a CustomPanel

·         File URL (file:/c:/…)

·         http URL (http://…)

The document is loaded via a blocking call that is run in the DashBoard User Interface thread.

Calls to load documents over a network(for example, usinghttp://) are stronglydiscouraged and can have undesired impactson the UI performance.

Syntax

ogscript.parseXML (Document);

Parameters

Parameter

Type

Required

Description

Document

String

Yes

XML document to parse.

Returns

XML Document

For more information about returns, refer to the following URL:

http://docs.oracle.com/javase/6/docs/api/org/w3c/dom/Document.html

Example

The following example loads an XML file from the web using an asynchronous http request. An XPath expression extracts data from the XML and displays it on a label.

functionmyFunc(pageContent)

{

var xmlPageContent = '<?xml version="1.0" encoding="UTF-8"?>\n' + pageContent;

var document= ogscript.parseXML(xmlPageContent); var nodeList=

ogscript.runXPath('/response/sports/sportsItem/leagues/leaguesIt

em/teams/teamsItem/name', document); var teamList = '<html>'; ogscript.debug(nodeList.getLength());

for (var i = 0; i < nodeList.getLength(); i++)

{

teamList = teamList + nodeList.item(i).getTextContent() + '<br/>';

}

ogscript.rename('resultLabel', teamList + '</html>');

}

 

ogscript.asyncPost('http://api.oursports.com/v1/sports/hockey/league/ teams/?_accept=text%6Axml&apikey=ksjdur7euejru47fkbos85kg', null, myFunc);