@UiHandler("select")
void onSelect(ClickEvent event)
{
String result = null;
Node contextNode = null;
String xmlValue = xmlIn.getText();
String xpathValue = xpath.getText();
String contextValue = context.getText();
String namespacesValue = namespaces.getText();
if (xmlValue == null || xmlValue.trim().length() == 0)
{
result = "No xml input given";
}
else if (xpathValue == null || xpathValue.trim().length() == 0)
{
result = "No xpath given";
}
if (namespacesValue != null && namespacesValue.trim().length() == 0)
{
namespacesValue = null;
}
try
{
Document document = new XmlParser().parse(xmlValue, namespacesValue);
if (contextValue != null && contextValue.trim().length() != 0)
{
contextNode = document.selectNode(contextValue);
}
else
{
contextNode = document;
}
List<Node> nodes = contextNode.selectNodes(xpathValue);
result = buildResult(nodes);
}
catch (XPathException e)
{
result = "Exception:\n" + e.getMessage();