From 3702a386fd0121bde1b1d02c65de66245e9518cc Mon Sep 17 00:00:00 2001 From: Daniel White Date: Fri, 13 Sep 2013 00:22:47 +1000 Subject: xmerl: Use context namespace declarations to resolve prefix node tests Previously, a match would not be found if the namespace prefix in the XPath query was not contained in the original document. This allows the `namespace' option to provide a prefix that will be resolved to a namespace URI. See Section 2.3 of the XPath 1.0 specification for the behaviour of 'NCName:*' node tests. --- lib/xmerl/src/xmerl_xpath.erl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lib/xmerl/src/xmerl_xpath.erl') diff --git a/lib/xmerl/src/xmerl_xpath.erl b/lib/xmerl/src/xmerl_xpath.erl index 9af632e9ac..be0e863ce4 100644 --- a/lib/xmerl/src/xmerl_xpath.erl +++ b/lib/xmerl/src/xmerl_xpath.erl @@ -713,10 +713,26 @@ node_test(_Test, node_test({wildcard, _}, #xmlNode{type=ElAt}, _Context) when ElAt==element; ElAt==attribute; ElAt==namespace -> true; -node_test({prefix_test, Prefix}, #xmlNode{node = N}, _Context) -> +node_test({prefix_test, Prefix}, #xmlNode{node = N}, Context) -> case N of - #xmlElement{nsinfo = {Prefix, _}} -> true; - #xmlAttribute{nsinfo = {Prefix, _}} -> true; + #xmlElement{nsinfo = {Prefix, _}} -> + true; + #xmlElement{expanded_name = {Uri, _}} -> + case expanded_name(Prefix, "_", Context) of + {Uri, _} -> + true; + _ -> + false + end; + #xmlAttribute{nsinfo = {Prefix, _}} -> + true; + #xmlAttribute{expanded_name = {Uri, _}} -> + case expanded_name(Prefix, "_", Context) of + {Uri, _} -> + true; + _ -> + false + end; _ -> false end; -- cgit v1.2.3