You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

xml-query

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-query - npm Package Compare versions

Comparing version

to
1.2.0

15

build/index.js

@@ -30,3 +30,3 @@ "use strict";

var prop = function (name) {
var node = first();
var node = get(0);
if (node) {

@@ -36,2 +36,14 @@ return node[name];

};
var text = function () {
var res = '';
each(function (node) {
if (node.type === 'text') {
res += node.value;
}
else {
res += xmlQuery(node).children().text();
}
});
return res;
};
return {

@@ -50,4 +62,5 @@ attr: attr,

size: size,
text: text,
};
};
module.exports = xmlQuery;

6

package.json
{
"name": "xml-query",
"version": "1.1.0",
"version": "1.2.0",
"description": "Super small library to retrieve values and attributes from the XML AST generated by xml-reader",
"main": "build/index.js",
"scripts": {
"test": "node test/test.js",
"test": "ava test/test.js",
"pretest": "tsc",

@@ -26,3 +26,3 @@ "prepublish": "npm test"

"devDependencies": {
"tape": "^4.5.1",
"ava": "^0.15.2",
"xml-reader": "0.0.6"

@@ -29,0 +29,0 @@ },

# XML Query
Super small (~50 sloc) library to retrieve values and attributes from the XML AST generated by xml-reader.
Super small (~60 sloc) library to retrieve values and attributes from the XML AST generated by xml-reader.

@@ -117,10 +117,48 @@ Easy-to-use jQuery-like interface.

### .text()
Get the combined text contents of each element, including their descendants
```javascript
xmlQuery(ast).find('subject').text(); // 'hello'
```
### .eq()
Returns a new XmlQuery object for the selected element by index
```javascript
xmlQuery(ast).children().eq(2); // xmlQuery object containing the 'subject' node
```
### .first()
Returns a new XmlQuery object for the first element. Same as `.eq(0)`
```javascript
xmlQuery(ast).children().first(); // xmlQuery object containing the 'from' node
```
### .last()
Returns a new XmlQuery object for the last element. Same as `.eq(length - 1)`
```javascript
xmlQuery(ast).children().last(); // xmlQuery object containing the 'body' node
```
### .length
Number of elements. Returns the same result as `.size()`
```javascript
xmlQuery(ast).children().length; // 4
```
### .size()
Number of elements. Returns the same result as `.length`
```javascript
xmlQuery(ast).children().size(); // 4
```