Hi,

I am using Jaxen for evaluating XPaths in JDOM documents. It is a great
tool! I have one problem however. When evaluating functions (sum to be
spesific), I get an org.jaxen.UnresolvableException from getFunction() in
org.jaxen.SimpleFunctionContext.

The XPath I run is:

sum(/root/giro/produkter/produkt/sum)

I run it on the following XML document.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE XML>
<root>
  <giro>
    <betaler>
      <sted>0168 Oslo</sted>
      <adresse>Melkeveien 2</adresse>
      <navn>Villy Vonka</navn>
    </betaler>
    <produkter>
      <produkt id="1">
        <produktlinje>Bukse</produktlinje>
        <sum>1000</sum>
      </produkt>
      <produkt id="2">
        <produktlinje>Jakke</produktlinje>
        <sum>2000</sum>
      </produkt>
      <produkt id="3">
        <produktlinje>Skjorte</produktlinje>
        <sum>500</sum>
      </produkt>
      <produkt id="4">
        <produktlinje>Slips</produktlinje>
        <sum>300</sum>
      </produkt>
      <suminkmva>3800</suminkmva>
      <sumeksmva>3000</sumeksmva>
    </produkter>
    <fakturanummer>93248347</fakturanummer>
    <belop>
      <kr>3800</kr>
      <ore>00</ore>
    </belop>
    <kid>93248347</kid>
    <betalingsfrist>20.01.2002</betalingsfrist>
    <fakturadato>20.01.2003</fakturadato>
  </giro>
</root>

When debugging I find that the functions referenced in the functions HashMap
of org.jaxen.SimpleFunctionContext has keys with namespaceURI=null, whereas
the namespaceURI that enters getFunction() is the empty String, "". This
means that a legal function sum isn't resolved as desired.

The following fixes my problem, yet without removing the root of the
problem. I have changed getFunction() of org.jaxen.SimpleFunctionContext to:

    public Function getFunction(String namespaceURI,
                                String prefix,
                                String localName )
        throws UnresolvableException
    {
        if ("".equals(namespaceURI)) {
            namespaceURI = null;
        }

        Object key = new QualifiedName( namespaceURI, localName );

        if ( this.functions.containsKey(key) )
            return (Function) this.functions.get( key );
        else
            throw new UnresolvableException( "Function " +
                                             prefix + ":" + localName );
    }

Is this a known problem or does it exist other resolutions?

Regards
Brynjar Glesnes
Entra Data AS, Hoffsveien 17, 0275 Oslo, Norway
+47 21 93 98 34 / +47 932 48 347 / +47 21 93 98 00
http://www.xmltransform.com



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to