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] namespace support
Date Tue, 06 Aug 2002 19:49:53 GMT
Hi,

On Tue, Aug 06, 2002 at 02:19:46PM -0500, Joe Germuska wrote:
> At 9:15 PM +0200 2002/08/06, Stefan Heimann wrote:
> >Hi,
> >
> >the digester does not support rules like that:
> >
> >'xforms:extension/jiomask:layout'
> >
> >I mean, rules with different namespaces.
> >
> >Might such a feature be useful?
> 
> 
> Actually, it does:
> http://jakarta.apache.org/commons/digester/api/org/apache/commons/digester/Rule.html#setNamespaceURI(java.lang.String)
> 
> It's just that the rules which are created by the convenience methods 
> on digester (such as "addObjectCreate" and "addSetProperties") don't 
> give you a way to set it.

What about Digester#setRuleNamespaceURI?

Look at the following code:

  public static void main(String[] args) {
    String fooNsUri = "http://www.foo.com";
    String barNsUri = "http://www.bar.com";
    String input =
      "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
      "<root xmlns:foo=\""+fooNsUri+"\" xmlns:bar=\""+barNsUri+"\">\n"+
      "  <foo:a>\n"+
      "    <bar:b/>\n"+
      "  </foo:a>\n"+
      "</root>";
    System.out.println(input);
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
    "org.apache.commons.logging.impl.SimpleLog");
    Digester dig = new Digester();
    dig.setNamespaceAware(true);
    Rule fooRule = new Rule() {
        public void begin(Attributes attrs) {
          System.out.println("fooRule begins.");
        }
      };
    fooRule.setNamespaceURI(fooNsUri);
    Rule barRule = new Rule() {
        public void begin(Attributes attrs) {
          System.out.println("barRule begins.");
        }
      };
    barRule.setNamespaceURI(barNsUri);

    dig.addRule("/root/foo", fooRule);
    dig.addRule("/root/foo/bar", barRule);
    
    try {
      dig.parse(new StringReader(input));
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

The output is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root xmlns:foo="http://www.foo.com" xmlns:bar="http://www.bar.com">
  <foo:a>
    <bar:b/>
  </foo:a>
</root>

But I also want the 2 rules to be called. Maybe I was not clear about
what I wanted. It's no problem if a rule should be namespaceaware with
only one namespace. But if you have a rule that should match two or
more elements in different namespaces you have a problem.

Bye,
  Stefan

-- 
Stefan Heimann       | http://www.stefanheimann.net
Brandensteinstr. 5   | http://www.cantaloop.org
D-79110 Freiburg     | http://cvsshell.sourceforge.net

--
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