diff --git a/src/Document.js b/src/Document.js index e8befaa..603a0e1 100644 --- a/src/Document.js +++ b/src/Document.js @@ -62,6 +62,10 @@ return this._original.childNodes(); } + count(xpath) { + return this.get(`count(${xpath})`); + } + encoding(enc = null) { return this._original.encoding(enc); } @@ -110,9 +114,10 @@ get(xpath) { const found = this.find(xpath); - if (found.length === 0) return null; + if (!found.length) return found; // found is not an array so we just return it. + if (found.length === 0) return null; // found is an empty array so we return null. - return found[0]; + return found[0]; // found is a non-empty array so we return the first element. } getDtd() {