Good day all,

Please could someone explain the rationale behind having (e.g.) Element.add 
(Attribute) return void, rather than a reference to self? This precludes 
chaining of add()s --
Element newEl = (new DefaultElement ("price")).add (new DefaultAttribute 
("currency", "GBP")).add (new DefaultAttribute ("amount", "10"));

This is considerably more succinct than the current code, where the adds 
must be separated: either
1.
Element newEl = (new DefaultElement ("price")).add (new DefaultAttribute 
("currency", "GBP"));
newEl.add (new DefaultAttribute ("amount", "10"));

// Yuk - orthogonality out of the window

or 2.
Element newEl = (new DefaultElement ("price"));
newEl.add (new DefaultAttribute ("currency", "GBP"));
newEl.add (new DefaultAttribute ("amount", "10"));
// Tidy but verbose.

This could also affect the syntax of the existing addText() and addCDATA() 
- both take a String and return void, they could perhaps return self 
(Element) instead?

Only addEntity() seems non-orthogonal - this takes a String and returns 
_Entity_, a reference to the Entity object just created.

---

I actually want to insert hard-coded XML fragments into an existing 
document, and it's becoming very long-winded. I'd be happiest to do
String xmlFragment = "<complexType mixed = 'true'> <sequence> <element 
ref='xyz' /> </sequence> </complexType>";
Element newEl = parser.parse (xmlFragment);
parentEl.add (newEl);

I need to have namespaces behaving sensibly, so that element xyz inherits 
the namespace of parentEl, etc. Is there any way to do this? Can I use 
SAXReader.read() to parse fragments? I haven't yet managed to get this to 
work, so I'm manually creating DefaultElements and DefaultAttributes and 
chaining them together.

Anyone have any suggestions?

Thanks to all - I _like_ this library.

Regards,
Thomas.


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

Reply via email to