[Haskell-cafe] Re: HXT Namespaces and XPath

Uwe Schmidt si at fh-wedel.de
Wed Apr 7 02:41:48 EDT 2010


Hi Mads,

> Replying to myself:
> 
> > I think another example will clarify my point. The code:
> > 
> > simpleXmlOne, simpleXmlTwo :: String
> > simpleXmlOne = "<a:Foo xmlns:a=\"http://foo.org\"/>"
> > simpleXmlTwo = "<b:Foo xmlns:b=\"http://foo.org\"/>"
> > 
> > nsEnv :: [(String, String)]
> > nsEnv = [ ("notFoo"    , "http://notfoo.org") ]
> > 
> > evalXPath :: String -> [XmlTree]
> > evalXPath xml =
> >   runLA ( xread
> >           >>> propagateNamespaces
> >           >>> getXPathTreesWithNsEnv nsEnv "//a:Foo"

this line contains the problem:

getXPathTreesWithNsEnv assumes, that for all prefixes used in the XPath expr,
the nsEnv contains an entry. Furthermore the default namespace
can be given by an entry for the empty prefix "".

So you'll only get reasonable results, when nsEnv contains at least an entry for "a", e.g.

nsEnv = [ ("a", "http://x.y"), ... ]

when you use the XPath expr "//a:Foo".

You may argue, that in your example, an error should be raised by the XPath parser, instead
of accepting "//a:Foo". But currently it's assumed, that getXPathTreesWithNsEnv is used
only in an innocent way.
 
Cheers,

  Uwe


More information about the Haskell-Cafe mailing list