haysclark / as3-xpath

1 stars 0 forks source link

Relative paths don't work when starting at the root node #23

Closed haysclark closed 9 years ago

haysclark commented 9 years ago

From peterj...@gmail.com on August 17, 2009 03:49:10

When you exec a path, it actually starts at an artificial wrapper node, that is created during the execution. This is because in XPath, the root node needs to be accessed with "/rootNodeName" not with "/"

The only time that this causes a problem is when you use the result of one expression as the input of another, and that result happens to be the root node. What steps will reproduce the problem? 1. xml = ;

var node = new XPathQuery("/root").exec( xml );

var name = new XPathQuery("./@name").exec( node );

name will be "", while if the first expression selected then the name would be "bar", which is clearly not consistent.

This is really a fact of life, but we can fix it for those times when you know it could happen, with an API change.

Original issue: http://code.google.com/p/xpath-as3/issues/detail?id=23

haysclark commented 9 years ago

From peterj...@gmail.com on August 17, 2009 04:04:06

XPathQuery.exec() now accepts an optional second argument, startNode. If this is not set, it will be taken to be the same as the first argument UNLESS the first argument is the document root, in which case it will be the document wrapper.

haysclark commented 9 years ago

From peterj...@gmail.com on August 17, 2009 04:05:37

Status: Fixed