Another idea around the concept of "context" (seems I like it !).
Element objects in a dom4j could be called "monomorphic", in the sense 
their state (content) is the same at a given time. Imagine you want to 
create Elements whose state will depend on some context defined after 
the time they were instanciated. This would be a kind of "polymorphism". 
I call those Elements "ActiveElements". Let's seen an example.

Original XML would look like this :
  <p>
    <language is="FR">
      Ceci est un paragraphe en Français.
    </language>
    <language is="EN">
      This is a paragraph in English.
    </language>
  </p>

With a context setting language to French, output would look like :

  <p>
    Ceci est un paragraphe en Français.
  </p>

A custom class, the LanguageElement would handle the content (both EN 
and FR languages), and recognize an application-specific context 
defining the language. Reading the LanguageElement content would deliver 
its content in the expected language.
Parsing would get easier, and would occur only once. The application 
would get simpler because it becomes the LanguageElement's 
responsability to deal with the 'language' aspect of the problem.

ActiveElements could be implemented to achieve some other goals.
- defining links whose target would be defined after the document was
entierly processed,
- defining text as pictures or characters depending of the target platform.
- ...

Cocoon already does something similar with XSL. In fact, it requires a 
much heavier kinematic : you have to re-generate XML each time you 
change the context. Xerces XNI has the same problem. On the other hand, 
ActiveElements allow to keep one DOM in memory for generating different 
documents with similar structures. They avoid one pass of XSLT or more.

I discovered dom4j while looking for a solution allowing to customize 
generated Elements (thanks to DocumentFactory class). The prototype 
works but the implementation lacks of elegance, since I'm creating a 
parallel hierarchy of Document, Branch, Element and Node.

I don't know if I found just a solution to a specific problem, or a more 
general tool. Tell me about what you think.





_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to