commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Heimann <m...@stefanheimann.net>
Subject Re: Re: [Digester] Enhancements, Namespace
Date Mon, 19 Aug 2002 22:11:22 GMT
Hi,

On Mon, Aug 19, 2002 at 02:56:37PM -0700, Craig R. McClanahan wrote:
> 
> 
> On Mon, 19 Aug 2002, robert burrell donkin wrote:
> 
> > Date: Mon, 19 Aug 2002 22:25:19 +0100
> > From: robert burrell donkin <robertburrelldonkin@blueyonder.co.uk>
> > Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> > To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> > Subject: Re: [Digester] Enhancements, Namespace
> >
> > On Sunday, August 18, 2002, at 02:31 PM, Stefan Heimann wrote:
> >
> > > Hi,
> >
> > hi Stefan
> >
> > i think that you can already match patterns like 'foo:a/bar:b'. what you
> > need to do is set namespace aware to false. (apologies since this really
> > should be in the documentation.)
> >
> 
> Setting namespace-aware to false, though, has a very negative consequence
> IIRC - you're stuck matching on the actual namespace prefix used in the
> instance document being processed.

Yes, that's bad.
 
> Namespace-aware parsing, on the other hand, lets you match against the
> local value, no matter what prefix a particular document author chose to
> use.  I haven't looked at the proposed patch, but it would be really nice
> to relax the "only one namespace" restriction without destroying the
> ability to have Digester smart about matching on the underlying namespace
> URIs instead of on the prefixes themselves.

Ok, I haven't posted the patch, because it's not only a change on one
class, but in severals (TestCase, Digester, RulesBase,...)

With my changes you could do the following:

Assume the following XML document:

<?xml version="1.0"?>
<foo:root xmlns:foo="http://www.foo.org" xmlns:bar="http://www.bar.org">
  <foo:a>
    <bar:b/>
  </foo:a>
  <bar:a>
    <foo:b/>
  </bar:a>
</root>

In your digester you could now write:

Digester dig = new Digester();
Rules rules = dig.getRules();
rules.registerNamespaceprefix("f", "http://www.foo.org");
rules.registerNamespaceprefix("b", "http://www.bar.org");

// matches both root/a/b structures, because there is no default 
// namespace registered
rules.add("root/a/b", new MyRule());

// matches only the first root/a/b structure
rules.add("root/f:a/b:b");

// matches only the second root/a/b structure
rules.add("root/b:a/f:b");

rules.setDefaultNamespaceURI("http://www.foo.org");
// now the pattern matches only the first root/a/b structure
// because names in the pattern without namespace prefix are
// mapped to a default namespace uri
rules.add("root/a/b:b", new MyRule());


Bye
  Stefan

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message