thanks -- this makes sense -- just wanted to make sure I'm not missing something hidden.

I did an intermediate hack -- buffering the InputStream and injecting the namespaces into the first element.  Not pretty, but it gets the job done.

ryan



On Fri, May 2, 2014 at 12:41 AM, Michael Kay <mike@saxonica.com> wrote:
If the input isn't namespace well-formed, then a normal XML parser will reject it. Saxon delegates the XML parsing, so there is no control over this at the Saxon level.

The best that Saxon offers is that you can choose your own XML parser.

It might be possible to construct a SAX parser that repairs the input as follows:

(a) create a non-namespace aware SAX parser (parsers such as Xerces still support a non-namespace-aware mode, though it is very rarely used)

(b) add a ContentHandler that detects the presence of undeclared namespace prefixes, and injects appropriate namespace declarations

If you construct this as an instance of XMLFilter, then you can nominate it to Saxon as your parser, and Saxon will only see the repaired input.

If you think this approach is beyond your skills, then a cruder approach might be to wrap your XML inside a wrapper element that declares all the necessary namespaces.

Michael Kay
Saxonica


On 2 May 2014, at 02:06, Ryan McKinley <ryantxu@gmail.com> wrote:

I am trying to parse some XML that uses namespace elements without declaring them.  This is from a service I do not control, so I can not fix the source.

Is there a way to tell the DocumentBuilder a default namespace?  Much like the XPathCompiler#declareNamespace("xxx", "http://path/to/xxx/");

My other option is to read the stream into a string and then find the right place to drop in the text so that saxon can read -- but I would like to avoid that

The current error is:

Error on line 1 column 114 
  SXXP0003: Error reported by XML parser: The prefix "xxx" for element "xxx:numhits" is not bound.

thanks
Ryan
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.  Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.  Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help