You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Mike Sparr - www.goomzee.com" <mi...@goomzee.com> on 2005/12/10 10:23:05 UTC

[Digester] assistance - namespace-aware processing (how to write rules for digest)

If I have a document (note the content element referencing external
namespace):

<document>
  <author name="John Doe" />
  <title>Some name of a document</title>
  <exerpt>A brief description of a quotable phrase from
document</exerpt>
  <content xmlns:myco="http://www.company.com/document/schema">
    <myco:heading>This is the heading of the document</myco:heading>
    <myco:sub-heading>This is the sub-heading of the
document</myco:sub-heading>
    <myco:body>
      This is the body content of the document 
      and I can have some text that references a 
      term that may require more explaination so 
      I add a strangeword<myco:footnote symbol="*" expr="refer to user
guide for more information" /> and this footnote will appear at 
      the bottom of the document.
    </myco:body>
  </content>
</document>

I am new to digester but understand I have to write getter/setter
classes to represent the different elements.  Can someone help with
writing the rules to digest this?  I would like some flexibility to have
zero, one or more namespaces declared in my <content> element and the
digester will "digest" the elements within these.

For example, this instance uses a namespace and scheme defined by myco,
but we may want just text with no namespaces, or use
xmlns:xhtml="http://www.w3.org/xhtml/schema" and embed html in the
document.

Where do I start?

Thanks!


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


Re: [Digester] assistance - namespace-aware processing (how to write rules for digest)

Posted by Simon Kitching <sk...@apache.org>.
On Sat, 2005-12-10 at 02:23 -0700, Mike Sparr - www.goomzee.com wrote:
> If I have a document (note the content element referencing external
> namespace):
> 
> <document>
>   <author name="John Doe" />
>   <title>Some name of a document</title>
>   <exerpt>A brief description of a quotable phrase from
> document</exerpt>
>   <content xmlns:myco="http://www.company.com/document/schema">
>     <myco:heading>This is the heading of the document</myco:heading>
>     <myco:sub-heading>This is the sub-heading of the
> document</myco:sub-heading>
>     <myco:body>
>       This is the body content of the document 
>       and I can have some text that references a 
>       term that may require more explaination so 
>       I add a strangeword<myco:footnote symbol="*" expr="refer to user
> guide for more information" /> and this footnote will appear at 
>       the bottom of the document.
>     </myco:body>
>   </content>
> </document>
> 
> I am new to digester but understand I have to write getter/setter
> classes to represent the different elements.  Can someone help with
> writing the rules to digest this?  I would like some flexibility to have
> zero, one or more namespaces declared in my <content> element and the
> digester will "digest" the elements within these.
> 
> For example, this instance uses a namespace and scheme defined by myco,
> but we may want just text with no namespaces, or use
> xmlns:xhtml="http://www.w3.org/xhtml/schema" and embed html in the
> document.
> 
> Where do I start?

There are a number of good resources for learning Digester.

There is a list of articles availabel on the wiki:
  http://wiki.apache.org/jakarta-commons/Digester/ArticlesAndTutorials

There is a general overview of digester in the javadoc:
http://jakarta.apache.org/commons/digester/commons-digester-1.7/docs/api/org/apache/commons/digester/package-summary.html

There are also a number of example applications available. They are
included in the source downloads for digester, or can be browsed
directly from the subversion repository:
http://svn.apache.org/repos/asf/jakarta/commons/proper/digester/trunk/src/examples/

Note that Digester's support for xml namespaces is quite weak; it was
originally written before namespaces existed and that shows. A rule can
be associated with a namespace; this ensures that the *last* element in
the match path is in the specified namespace. However there is no
control over namespace-matching for the other parts of the path. As am
example, a rule with path "foo/bar/baz" and namespace "urn:ns1" will
only match baz elements in the specified namespace, but foo and bar will
match elements in any namespace. This looks like it will be acceptable
for your purposes though.

Once you have read the available info, I'm happy to answer any specific
questions you may have...


Regards,

Simon



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