Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

XML descendant problem #43

@ScottFreeCode

Description

@ScottFreeCode

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 />")
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions