Hi,

I've run the Xalan example ApplyXPathDOM with foo.xml, now I am trying to get it to work with namespaces.

I do not understand the FAQ http://xml.apache.org/xalan-j/faq.html#faq-N101BE where it says, "add a namespace declaration with a prefix".

Well, that's what I THINK I've been doing, but I still cannot get ApplyXPathDOM to run. I modified foo.xml with prefixes and a namespace (fooprefix.xml), but I still get errors when I run ApplyXPathDOM.

I've got setNamespaceAware(true) .

<?xml version="1.0"?>
<foo:doc xmlns:foo="http://foo.org";>
  <foo:name first="David" last="Marston"/>
  <foo:name first="David" last="Bertoni"/>
  <foo:name first="Donald" last="Leslie"/>
  <foo:name first="Emily" last="Farmer"/>
  <foo:name first="Joseph" last="Kesselman"/>
  <foo:name first="Myriam" last="Midy"/>
  <foo:name first="Paul" last="Dick"/>
  <foo:name first="Stephen" last="Auriemma"/>
  <foo:name first="Scott" last="Boag"/>
  <foo:name first="Shane" last="Curcuru"/>
</foo:doc>

I try to access this file with the expression:

java ApplyXPathDOM fooprefix.xml /foo:doc/[EMAIL PROTECTED]'David']

but still get this error:

Exception in thread "main" org.w3c.dom.DOMException: Prefix must resolve to a namespace: foo
at org.apache.xpath.domapi.XPathEvaluatorImpl.createExpression(XPathEval
uatorImpl.java:206)
The ONLY way I can force this to work is if I subclass XPathNSResolverImpl and hard code it with
a hashtable containing all the prefixes and namespaces I anticipate in a file, then forcing it to return
the appropriate URI for a prefix.


Then in ApplyXPathDOM I make the following modification:

      //XPathNSResolver resolver = evaluator.createNSResolver(doc);
      XPathNSResolver resolver = new DataServerNSResolverImpl(doc);


This is not an acceptable solution for us. I would expect ApplyXPathDOM to work automatically recognizing fooprefix.xml, without my subclass.


Somebody on a Sun Forum suggested I need a different a different sort of factory instance and then totally failed to specify which one.


-- Susan



Reply via email to