google / wicked-good-xpath Goto Github PK
View Code? Open in Web Editor NEWPure JS implementation of the DOM Level 3 XPath specification
License: MIT License
Pure JS implementation of the DOM Level 3 XPath specification
License: MIT License
Switch from our custom src/compiler.sh
to using https://github.com/ChadKillingsworth/closure-compiler-npm so that people don't have to download the Closure tools manually.
What steps will reproduce the problem?
1. Extract the attached zip file
2. Open the "test.html" file with IE
3. Click on the text box saying "click here"
What is the expected output? What do you see instead?
The expected output if an alert box with the Id of the text box "NOTWorksId",
what I see instead is an error message saying: "Object doesn't support property
or method 'each'"
What version of the product are you using? On what operating system?
Tested with the latest version and the error still occurs
Please provide any additional information below.
It only reproduces on IE8, I added the following tag to reproduce it also on
IE9:
"<meta http-equiv="X-UA-Compatible" content="IE=8" />"
Also, the order in which the scripts are added to the page matter, when
switching them so that "wgxpath.install.js" will be before the "otherScript.js"
it work fine. Unfortunately this is not an option for us.
We deliver some code together with wgxpath as a 3rd party for other sites to
use, some sites have javascript similar to the javascript in the
"otherScript.js" file, so we have no control over it.
You can place a breakpoint in the "filter" method in the "otherScript.js" file
just before the error happens.
Original issue reported on code.google.com by [email protected]
on 11 Feb 2013 at 10:58
Attachments:
To reproduce:
for This issue, I'm evaluating feFood svg control by wgxpath. If xpath passed to evaluate function is case-sensitive, then we get no result.
Sample:
feFood_sample.zip
Where can I get the non minified version of this lib?
Original issue reported on code.google.com by [email protected]
on 7 Jan 2014 at 9:50
Call document.evaluate() on an expression that returns a scalar, but expect a
node to be returned. For example:
document.evaluate("count(//input)", document.documentElement, null, 9);
When using the uncompiled library, an exception is thrown. This is what I would
expect to happen, and what WebDriver expects to happen. When using the
Closure-compiled version of the library, no exception is thrown.
I've attached an HTML file that demonstrates the problem. You can modify the
source of the HTML file to use the compiled or uncompiled version of the
library (adjusting the source paths to your local environment).
Original issue reported on code.google.com by [email protected]
on 13 Sep 2012 at 2:35
Attachments:
Using input XML as:
<WG:R xmlns:WC="cNamespace" xmlns:WG="gNamespace" AF="22"><WG:F Id="22"/></WG:R>
Namespace resolver as:
` function Xml_NSResolver(strPrefix) {
if (strPrefix == "WG") {
return 'gNamespace';
}
else if (strPrefix == "WC") {
return 'cNamespace';
}
return null;
}`
The script initialized by:
mobjXpathEngineWindow = { document: {} };
wgxpath.install(mobjXpathEngineWindow);
Then calling evaluate as:
All the above xpath queries work fine in online xpath testers.
Attached is a fully contained test.html for these tests.
Palli
dist.zip
please add dist folder for bower package
Hi guys,
Was using your wonderful library and unfortunately stumbled upon a specific xpath scenario where Google Chrome xpath resolver works fine, but Wicked Good Xpath fails to evaluate.
Basically in HTML structure like the one in JS Fiddle, nothing except DIV can be evaluated from the container.
Please tell me I am dumb and using it incorrectly :)
Please see the JS fiddle:
https://jsfiddle.net/xfwdybn7/
More a feature request then a real issue I guess..
Would be nice to get a usage like:
xml.evaluate( etc....
wgxpath.install(window,node)
Original issue reported on code.google.com by [email protected]
on 22 Oct 2012 at 1:54
Sorry if this doesn't belong here, but maybe you can help. I have some code
that works on Chrome and Firefox but not on IE (any version as far as I can
tell). Basically, the paths work just fine but the expressions do not. I am not
sure what other information I can provide other than the attached example.
Open a web page, press F12 to open the debugger, go to the script tab, choose
the "Console" tab on the right, and copy-paste the attached code.
"successNodes" has two elements and "success" points to the first; "failNodes"
has no elements and "fail" is null.
Original issue reported on code.google.com by [email protected]
on 1 Mar 2013 at 6:00
Attachments:
The description stated sootvetsivie documentation W3 (DOM Level 3 XPath), but,
in this case, is entirely absent implementation XPathNSResolver. The plans of
this?
If not, whether you want to open the source code for the private implementation?
Thank you for your work and thank you for any response!
Original issue reported on code.google.com by [email protected]
on 16 Mar 2013 at 4:32
I changed the value of the textarea tag on W3School [1]. After that, I try to evaluate textarea's xpath [2] on W3School [1] on IE but it doesn't work!
I have tried that xpath on Firefox, Chrome and it works fine.
[1] : http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea
[2] : //textarea[contains(.,'At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.')]
The following copyright notice appears 24 times in the 1.0 pre-compiled version of wgxpath.install.js. r23 had this comment zero times. Also, r23 was 27k, while 1.0 is 41k. Removing the comments restores the old size.
/*
Copyright 2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
I have downloaded the node source and required the module:
XPath=require('./util/wgxpath');
XPath.install();
it gives no errors.
But now how to evaluate an available DOM and valid structure (supposed to have one within node)?
On a browser I have copied the install file in the Chrome console
and the I did
wgxpath.install()
But I cannot see there the .test
object
wgxpath.test
undefined
At the moment names are matched with a "simple" \w
regex in the lexer however I dug a bit into the production and it seems it all ends up in a NameChar which matches a much larger array of values.
Is that correct, should we expand the regex to match the full range of NameChars?
What steps will reproduce the problem?
1.Write and complex expression like
"/DecosReport/Query[@ItemType='DOCUMENT'][@Level='0']/Queries/Query"
2. Try to use document.evaluate(cXPathString, xNode, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
Function should give snapshotitem? There is not snapshotitem.
I am using IE 11 on windows 8.1.
This is on high priority. Please take a look, thanks in advance.
Original issue reported on code.google.com by [email protected]
on 27 Feb 2014 at 9:42
Attachments:
What steps will reproduce the problem?
1. Create a document with a prefixed element, i.e. <ns:element>
2. Output the local name of said element, i.e. evaluate("local-name(*)")
What is the expected output? What do you see instead?
The local-name should be "element", regardless of prefix used in the markup.
The local-name returned by wgxpath is "ns:element".
(compare http://www.w3.org/TR/xpath/#function-local-name)
What version of the product are you using? On what operating system?
wgxpath r20, IE11, Windows 7.
Please provide any additional information below.
I already found and test-hotfixed the relevant parts of the code, tho I only
found the minimized version of it to work with.
Compare the 2 XPath functions local-name and name:
V("local-name",3,!1,!0,function(a,b){var c=b?Xa(b.a(a)):a.a;return
c?c.nodeName.toLowerCase():""},0,1,!0)
V("name",3,!1,!0,function(a,b){var c=b?Xa(b.a(a)):a.a;return
c?c.nodeName.toLowerCase():""},0,1,!0)
They are identical. "local-name" shouldn't access the "nodeName" property, but
rather "localName"
(http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-NodeNSLocalN).
When you replace local-name's "nodeName" with "localName", the testcase
outlined above works as expected.
Additionally, selecting a prefixed element fails completely (i.e. evaluating
"/ns:element" on the document above), the relevant code for that seems to be
K.prototype.a=function(a){var b=a.nodeType;return
1!=b&&2!=b?!1:"*"!=this.h&&this.h!=a.nodeName.toLowerCase()?!1:this.c==(a.namesp
aceURI?a.namespaceURI.toLowerCase():"http://www.w3.org/1999/xhtml")};
Changing "nodeName" to "localName" here allows queries of the syntax
"ns:element" to find something. The function looks a little bit too mystical to
say what else this change would cause, so not sure about this one.
Original issue reported on code.google.com by [email protected]
on 8 Apr 2014 at 5:36
I noticed there haven't been any commits to this library since 2017. Is this because the library is extremely stable/no longer needs updates? Or does it need a maintainer?
To reproduce:
1. Open a document with wgxpath loaded and a <div> containing an <svg>
2. wgxpath.install()
3. document.evaluate('//div/svg',document.body).iterateNext()
Expectation: an <svg> element is returned
Result: null is returned
Revision: 21
It seems to be just the child axis which is failing; using the xpath expression
'//div//svg', the expected <svg> element is returned, yet no amount of wildcard
children added ('//div/*/svg', '//div/*/*/svg', etc) produce the same result.
Original issue reported on code.google.com by [email protected]
on 6 Aug 2014 at 3:08
Is it possible to use this library in react projects?
Hi,
I create a framework which use Evaluate, I know how to detect if this method is available but I would like to detect if wgxpath.install.js is loaded, an if wgxpath.install() is executed, and at last, if wgxpath.install() failed or not in both case my framework call it or browser did it before to initialize my framework.
A Wiki or documentation about these issues could be fine.
An XPath expression that uses a namespace registered under an other prefix than
in the XML document fail to be evaluated in IE9 and IE10 whereas this works in
Chrome, Firefox and Opera.
The problem was encountered with the r16 but seems to also appear in r17.
In the attached file, I give you an example that reproduce the problem.
Original issue reported on code.google.com by [email protected]
on 7 May 2013 at 2:35
Attachments:
My applications get XML documents from HTTPRequest.responseXML and DOMParser.
How difficult is it to extend your solution so that your solution for document
also works on these other objects?
Original issue reported on code.google.com by [email protected]
on 25 Mar 2013 at 8:41
The library throws error when the element names in xpath has period (.) in it.
To reproduce the problem
1. Create an XML Document with period in element names. Using jQuery you can
create the document using the code
var xml = "<abc><a.d>12</a.d></abc>";
var xmlDoc = $.parseXML(xml);
wgxpath.install();
var result = document.evaluate("/abc/a.d",xmlDoc, null, XPathResult.ANY_TYPE, null);
2. The same script runs on Chrome which provides native support for
document.evaluate but not on IE11 using this library. It fails with an error
SCRIPT5022: Bad token: .
File: wgxpath.install.js, Line: 47, Column: 609
3. I have created a fiddle http://jsfiddle.net/r0gruz30/ which reproduces the
problem. Open the fiddle in chrome and the output will be *Result is 12* but in
IE the output is *Result is* and there is an error in the console
SCRIPT5022: Bad token: .
File: wgxpath.install.js, Line: 47, Column: 609
I am using the latest wgxpath library and seeing the issue on IE11 windows 7.
I debugged the code and found that the reason for the issue is in lexer.js. The
regular expression for _TOKEN does not takes care of periods in element names.
So if I change the regex
wgxpath.Lexer.TOKEN_ = new RegExp(
'\\$?(?:(?![0-9-])[\\w-]+:)?(?![0-9-])[\\w-]+' +
...
.....,
'g')
to
wgxpath.Lexer.TOKEN_ = new RegExp(
'\\$?(?:(?![0-9-\\.])[\\w\\.-]+:)?(?![0-9-\\.])[\\w-\\.]+' +
...
.....,
'g')
it works.
Original issue reported on code.google.com by [email protected]
on 24 Feb 2015 at 10:57
wgxpath.NodeSet.merge depends upon the result of the xpath inheriting from Node, and in particular being able to compare the node order, e.g. when doing //img/@src
TypeError: Cannot read property 'createRange' of undefined
at Object.b.dom.compareNodeOrder (wgxpath.install-node.js:255:276)
at Function.f.NodeSet.merge (wgxpath.install-node.js:281:723)
at [object Object].f.PathExpr.evaluate (wgxpath.install-node.js:317:13)
at [object Object].evaluate (wgxpath.install-node.js:344:370)
at Document.e.evaluate (wgxpath.install-node.js:350:286)
What do you think the best solution for this is? Perhaps wrapping the Attr instance in a Node wrapper? Unfortunately the spec[1] doesn't even have a link back to the owning element (which actually seems to contradict some of the text within the section).
What steps will reproduce the problem?
1. Create a page and include the script
2. open console and type: !!('evaluate' in document)
3.
What is the expected output? What do you see instead?
result is false should be true. Tested in IE 8,9,10
What version of the product are you using? On what operating system?
Latest 13-09-2013. W7 32 bit
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 23 Sep 2013 at 1:14
In nodejs, I use jsdom 15.2.0 to parse the html source code.
It works well for most XPaths except when the path is to an attribute, such as //div/@Class.
TypeError: Cannot read property 'createRange' of undefined at La (/var/www/api/node_modules/wicked-good-xpath/dist/wgxpath.install-node.js:42:35) at Pa (/var/www/api/node_modules/wicked-good-xpath/dist/wgxpath.install-node.js:42:645) at kb.a (/var/www/api/node_modules/wicked-good-xpath/dist/wgxpath.install-node.js:57:328) at Nb.evaluate (/var/www/api/node_modules/wicked-good-xpath/dist/wgxpath.install-node.js:73:1130) at Document.Pb.d.evaluate (/var/www/api/node_modules/wicked-good-xpath/dist/wgxpath.install-node.js:77:159)
Is there any other library that is fully compatible with wgxpath? or any other workaround?
Is there any plan to add an implementation of XPath Axes? I have found none
that work in IE when using Selenium - which to my knowledge includes
wicked-good-xpath for XPath emulation in IE.
https://developer.mozilla.org/en-US/docs/Web/XPath/Axes
Original issue reported on code.google.com by [email protected]
on 12 Dec 2014 at 6:40
Any namespace qualified step in XPath returns no data.
If "ns:elem1/*" returns elements in the namespace associated with the ns
prefix, then "ns:elem1/ns:*" does not.
Original issue reported on code.google.com by [email protected]
on 3 Apr 2013 at 11:58
As seen in binaryExpr.js where there is a primitive value and a nodeset, the nodeset is always passed as the first argument to the comp
function. This will obviously give the wrong result with the ordering comparisons ('<', '<=', '>', '>=').
98e8b0e breaks compatibility with IE8.
Errors look like this:
TypeError: 'localName' is null or not an object
What steps will reproduce the problem?
1. Run the attached html page on IE, Chrome, FF
2. Notice that the XPath result is different on IE than it is on Chrome/FF
What is the expected output? What do you see instead?
I expect the results on IE to be 'string' but I see nothing.
What version of the product are you using? On what operating system?
Version available on October 8, 2014
Please provide any additional information below.
Thanks.
Original issue reported on code.google.com by [email protected]
on 8 Oct 2014 at 6:52
Attachments:
The use of an XPath expression with some namespace prefixes doesn't work
anymore in r17. This affects IE9 and IE10.
This concerns prefixes declared in the XML document, not the default namespaces.
The attached file contains an example that reproduces the problem.
Original issue reported on code.google.com by [email protected]
on 7 May 2013 at 2:42
Attachments:
What steps will reproduce the problem?
The below standalone example code works in the native implementations of XPath
in Chrome and Firefox but fails with wgx (in IE 11, as well as Chrome and
Firefox if I force them to use wgx).
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<kml xmlns="http://www.opengis.net/kml/2.2" \
xmlns:gx="http://www.google.com/kml/ext/2.2">\
<Document>\
<Placemark>\
<gx:Track>\
<when>2010-05-28T02:02:09Z</when>\
<gx:coord>7 8 9</gx:coord>\
</gx:Track>\
</Placemark>\
</Document>\
</kml>';
var xmlDocument = new DOMParser().parseFromString(kml, "text/xml");
var namespaces = {
kml : 'http://www.opengis.net/kml/2.2',
gx : 'http://www.google.com/kml/ext/2.2'
};
function namespaceResolver(prefix) {
return namespaces[prefix];
}
var iterator = window.document.evaluate('./kml:Document/kml:Placemark',
xmlDocument.firstChild, namespaceResolver, window.XPathResult.ANY_TYPE, null);
var pm = iterator.iterateNext(); // correct
iterator = window.document.evaluate('gx:Track', pm, namespaceResolver,
window.XPathResult.ANY_TYPE, null);
var track = iterator.iterateNext();
alert(track); //null; should be the track element
What is the expected output? What do you see instead?
The variable "track" should be the gx:Track node in the reference XML, it is
null instead.
What version of the product are you using? On what operating system?
I'm using the build trunk from Oct 3rd. I downloaded
https://code.google.com/p/wicked-good-xpath/source/browse/trunk/build/wgxpath.in
stall.js and am using it as-is.
Win7 x64
Please provide any additional information below.
As I stated, the native implementations work in Chrome and Firefox.
Original issue reported on code.google.com by [email protected]
on 11 Nov 2014 at 10:07
From discussion of #7, XML documents don't seem to be finding descendants (EDITTED: this list has been updated so that the checkbox indicates whether the native implementation is matched and the + or - afterward indicates whether the native implementation gets a result for the expression):
//Root
//Menu
/descendant::Root
/descendant::Menu
/descendant-or-self::Root
/descendant-or-self::Menu
//self::Root
//self::Menu
//*[self::Root]
//*[self::Menu]
/Root//Root
/Root//Menu
/Root/descendant::Root
/Root/descendant::Menu
/Root/descendant-or-self::Root
/Root/descendant-or-self::Menu
/Root//self::Root
/Root//self::Menu
/Root//*[self::Root]
/Root//*[self::Menu]
This appears to affect all browsers, provided the override is used to force install.
List generated by this code in case anyone wants to clean it up and make some kind of test out of it or tinker with it and see if anything else affects whether it works (EDITTED):
var wgx = {}
wgxpath.install({document: wgx})
var src = '<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE Root><Root><Menu ID="11"></Menu></Root>'
var xml = new DOMParser().parseFromString(src, "application/xml")
var prefixes = ["//", "/descendant::", "/descendant-or-self::", "//self::", "//*[self::"]
prefixes = prefixes.concat(prefixes.map(function(prefix) {
return "/Root" + prefix
}))
prefixes.forEach(function(prefix) {
["Root", "Menu"].forEach(function(tag) {
var resultWGX = wgx.evaluate(prefix + tag + (/[[]/.test(prefix)?"]":""), xml, wgx.createNSResolver(xml), XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
var resultNative = xml.evaluate(prefix + tag + (/[[]/.test(prefix)?"]":""), xml, xml.createNSResolver(xml), XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
document.write("- [" + (resultWGX===resultNative?"x":" ") + "] " + (resultNative?"+":"-") + " `" + prefix + tag + (/[[]/.test(prefix)?"]":"") + "`<br />")
})
})
(EDITTED: the old list was generated by this code, which works on browsers that have no native implementation, but does not compare against the native implementation to automatically identify the few expression combinations that wouldn't work anyway:)
wgxpath.install(window, true)
var src = '<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE Root><Root><Menu ID="11"></Menu></Root>'
var xml = new DOMParser().parseFromString(src, "application/xml")
var prefixes = ["//", "/descendant::", "/descendant-or-self::", "//self::", "//*[self::"]
prefixes = prefixes.concat(prefixes.map(function(prefix) {
return "/Root" + prefix
}))
prefixes.forEach(function(prefix) {
["Root", "Menu"].forEach(function(tag) {
var result = xml.evaluate(prefix + tag + (/[[]/.test(prefix)?"]":""), xml, xml.createNSResolver(xml), XPathResult.ANY_TYPE, null)
document.write("- [" + (result.iterateNext()?"x":" ") + "] `" + prefix + tag + (/[[]/.test(prefix)?"]":"") + "`<br />")
})
})
Using xpath expressions with a wildcard select for nodes doesnt return any results:
I will be using this as my sample document
<MyDocument xmlns="http://testschema.com/">
<ParentNode>
<ChildNode />
</ParentNode>
</MyDocument>
Then if you run this xpath query /a:MyDocument/a:Parent/*
you will get 0 results. You can make the xpath query work by replacing the single /
with a double //
before the wildcard. /a:MyDocument/a:Parent//*
.
I did make a Plunker for testing this. The Plunker is using a wgxpath install which overwrites the document.evaluate
method so you dont have to run it on IE to test it.
Because the the node lack of a native xml support.
So pure js xml lib on nodejs is very necessary.
The present, xmldom(https://npmjs.org/package/xmldom) can solve most of the xml
parsing problem, but no xpath support.
Original issue reported on code.google.com by [email protected]
on 7 Sep 2012 at 3:15
Great library. How to run the tests?
Original issue reported on code.google.com by [email protected]
on 11 Mar 2015 at 6:03
"main" in bower.json is set to get dist folder files that is not pushed.
Please add dist folder with compiled files to use directly this modules.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.