1
0
mirror of synced 2024-11-28 00:20:48 +01:00

Added operation: "XPath expression"

This commit is contained in:
Mike Schwörer 2016-11-29 19:28:07 +01:00
parent 09d515cbae
commit 51b627ab29
No known key found for this signature in database
GPG Key ID: D3C7172E0A70F8CF
6 changed files with 6464 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ build/dev
docs/*
!docs/*.conf.json
!docs/*.ico
.idea/*

View File

@ -123,6 +123,7 @@ module.exports = function(grunt) {
"src/js/lib/vkbeautify.js",
"src/js/lib/Sortable.js",
"src/js/lib/bootstrap-colorpicker.js",
'src/js/lib/jquery.xpath.js',
// Custom libraries
"src/js/lib/canvas_components.js",

View File

@ -186,6 +186,7 @@ var Categories = [
"Extract file paths",
"Extract dates",
"Regular expression",
"XPath expression",
]
},
{

View File

@ -1893,6 +1893,24 @@ var OperationConfig = {
},
]
},
"XPath expression": {
description: "Extract information from an xml document with an XPath query",
run: Extract.run_xpath,
input_type: "string",
output_type: "string",
args: [
{
name: "XPath",
type: "string",
value: Extract.XPATH_INITIAL
},
{
name: "Result delimiter",
type: "binary_short_string",
value: Extract.XPATH_DELIMITER
}
]
},
"From UNIX Timestamp": {
description: "Converts a UNIX timestamp to a datetime string.<br><br>e.g. <code>978346800</code> becomes <code>Mon 1 January 2001 11:00:00 UTC</code>",
run: DateTime.run_from_unix_timestamp,

6380
src/js/lib/jquery.xpath.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
var Extract = {
/**
* Runs search operations across the input data using refular expressions.
* Runs search operations across the input data using regular expressions.
*
* @private
* @param {string} input
@ -293,5 +293,66 @@ var Extract = {
output += Extract.run_dates(input, []);
return output;
},
/**
* @constant
* @default
*/
XPATH_INITIAL: "",
/**
* @constant
* @default
*/
XPATH_DELIMITER: "\\n",
/**
* Extract information (from an xml document) with an XPath query
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run_xpath:function(input, args) {
var query = args[0];
var delimiter = args[1];
try {
var xml = $.parseXML(input);
} catch (err) {
return "Invalid input XML.";
}
try {
var result = $.xpath(xml, query);
} catch (err) {
return "Invalid XPath. Details:\n" + err.message;
}
var serializer = new XMLSerializer();
var output = "";
for (var i = 0; i < result.length; i++) {
if (i > 0) output += delimiter;
switch (result[i].nodeType) {
case Node.ELEMENT_NODE:
output += serializer.serializeToString(result[i]);
break;
case Node.ATTRIBUTE_NODE:
output += result[i].value;
break;
case Node.TEXT_NODE:
output += result[i].wholeText;
break;
case Node.COMMENT_NODE:
output += result[i].data;
break;
default:
throw new Error("Unknown Node Type: " + result[i].nodeType);
}
}
return output;
}
};