Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

I haven't looked closely at the XML libraries with SM, but, I didn't see any mention of Xpath. Is there a way to use an existing jar file with SM for Xpath support?

Anyone gone this route yet with pointers on exactly what to do?

  • 4 weeks later...

Looks like XPath functionality is included with Java, since Java 1.5

http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/xpath/XPath.html

Please let us know if you're interested in us estimating a custom ScriptMaster module for you.

  • 3 months later...

I created this with the help of some folks at StackOverflow:

RegisterGroovy( "XPath( xml ; query )" ; "// XPath (xml, query)¶

// Created by Jack James with help from StackOverflow.com¶

// Version 1 16/02/10¶

¶

import javax.xml.xpath.*¶

import javax.xml.parsers.DocumentBuilderFactory¶

¶

def processXml( String xml, String xpathQuery ) {¶

  def xpath = XPathFactory.newInstance().newXPath()¶

  def builder     = DocumentBuilderFactory.newInstance().newDocumentBuilder()¶

  def inputStream = new ByteArrayInputStream( xml.bytes )¶

  def records     = builder.parse(inputStream).documentElement¶

  def nodes       = xpath.evaluate( xpathQuery, records, XPathConstants.NODESET )¶

  nodes.collect { node -> node.textContent }¶

¶

}¶

¶

processXml( xml, query )" )

Put that in a step variable and call it with the xml to process as the first parameter and the XPath query as the second.

It's fairly basic, so if anyone wants to expand on it, be my guest (I know nothing of java/groovy unfortunately)

Thanks!

If you don't mind we'll add this to the next release of ScriptMaster.

  • 3 months later...

Very simple xml query for a simple

fm_fileIn contains

fm_query = any valid node

returns the node value or '0' if empty or not exist

RegisterGroovy( "XmlSlurp( fm_fileIn ; fm_query )" ; "// XmlSlurp(fm_fileIn ; fm_query )¶

// 15_06_10 JR¶

// v1¶

¶

xs = new XmlSlurper().parseText(fm_fileIn)¶

ln = xs."${fm_query}".size()¶

if ( ln == 1 ) {¶

	return xs."${fm_query}".text().trim()¶

} else return false¶

¶

// finds length of trimmed node¶

//xs."${fm_query}".text().trim().toString().length()" )

  • 2 months later...

Please note that the current version of the XPath function (as distributed with SM4) will break if you attempt to input xml with UTF-8 encoded characters and no header.

You can force it to always accept UTF-8 by making the following change:

InputStream inputStream = new ByteArrayInputStream( someXML.getBytes("utf-8"));

Thank you, we'll add this to the next release.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.