You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Marwan Aziz <ma...@yahoo.com> on 2003/11/21 18:26:04 UTC

NodeCreateRule Question

Hello All,
 
I have an XML file that looks like the following:
<a>
   <b>
      <c/>   <b/>
   <b>
      <c/>
   </b>

</a>
 
I also have the following rules defined:
digester.addFactoryCreate("a/b", ....);
digester.addSetProperties("a/b");
digester.addSetNExt("a/b", ....);
digester.addObjectCreate("a/b/c", ....);
digester.addSetProperties("a/b/c");
digester.addSetNext("a/b/c", ....);
 
This works fine. What I want to do also is to "extract" the <b> element (and its subelement) and then insert it into another XML document. I recognize that I have to use the NodeCreateRule, however, I am not sure where to place the rule. From the docs, it is mentioned that "rules that would match XML nodes under the element that matches a NodeCreateRule will never be triggered by Digester, which usually is the behavior one would expect.". Is it possible to mix NodeCreateRule with FactoryCreateRule?? or should I parse the file again to extract the nodes??
 
Thanx for the help in advance.
 
- Marwan
 


---------------------------------
Do you Yahoo!?
Free Pop-Up Blocker - Get it now

Re: NodeCreateRule Question

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Sat, 2003-11-22 at 06:26, Marwan Aziz wrote:
>  
> I also have the following rules defined:
> digester.addFactoryCreate("a/b", ....);
> digester.addSetProperties("a/b");
> digester.addSetNExt("a/b", ....);
> digester.addObjectCreate("a/b/c", ....);
> digester.addSetProperties("a/b/c");
> digester.addSetNext("a/b/c", ....);
>  
> This works fine. What I want to do also is to 
> "extract" the <b> element (and its subelement) 
> and then insert it into another XML document. 
> I recognize that I have to use the NodeCreateRule, 
> however, I am not sure where to place the rule. 
> From the docs, it is mentioned that "rules that 
> would match XML nodes under the element that matches 
> a NodeCreateRule will never be triggered by Digester,
>  which usually is the behavior one would expect.". 
> Is it possible to mix NodeCreateRule with FactoryCreateRule??
>  or should I parse the file again to extract the nodes??

You will need to parse the file again. Using NodeCreateRule will prevent
any rule-matching against input "beneath" the node that is being used.

NodeCreateRule basically detaches Digester from the XML parser and
handles the incoming SAX events itself until the end of the matching
node is reached. So Digester never even knows that the elements under
the matching node exist.

It would be great to have a better way to handle this in Digester. If
you can come up with an implementation that allows both the node and
rules, please submit it! I think that it could be possible, by inserting
a "sax filter" between the parser and the Digester rather than
completely redirecting the events as is currently done.

Regards,  Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org