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.

Simple XPath with namespaces not working #60

Description

@pallibj

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:

  • evaluate("//WG:F[@id='22']", objContext, Xml_NSResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) - no results
  • evaluate("//WG:F[@*[local-name()='Id']='22']", objContext, Xml_NSResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) - no results
  • evaluate("//[local-name()='F' and namespace-uri()='gNamespace'][@[local-name()='Id']='22']", objContext, Xml_NSResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) - no results
  • evaluate("//[local-name()='F'][@[local-name()='Id']='22']", objContext, Xml_NSResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) - Gives results, but doesn't distinguish namespaces so unusable.

All the above xpath queries work fine in online xpath testers.

Attached is a fully contained test.html for these tests.

Palli
dist.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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