RE: [libxml++] Rename Element::add_content() to add_text_content?



Dan Dennedy wrote:
> On Thu, 2003-10-23 at 10:16, Murray Cumming Comneon com wrote:
> > I think we should rename these xmlpp::Element methods like so:
> > add_content() -> add_text_content() or maybe add_text().
> > get_child_content() -> get_child_text_content() or maybe 
> > get_child_text()
> > Set_child_content() -> set_child_text_content() or maybe 
> set_child_text()
> > 
> http://libxmlplusplus.sourceforge.net/reference/html/classxmlp
> p_1_1Element.h
> > tml
> > because that is what they do.
> 
> I like add_text, set_text, and get_text without referring to 
> child. child is more or less implied. Lest you think someone 
> confuse it with the element name?

I think it's useful to have _child_ in the name, because
1. It avoids confusion between std::string Element::get_text() and
std::string ContentNode::get_content()
2. It makes it clearer that it's _1_ child node rather than some
concatenation of all child text nodes. We don't do that because it would be
useless to skip over other nodes.


> > And that makes more sense now that we have added add_comment().
> 
> Please add:
> CommentNode* Document::add_comment(const std::string& content) {
>   xmlNode* node = xmlNewComment((xmlChar*)content.c_str());
>   xmlAddChild( (xmlNode*) _impl, node);
>   return static_cast<CommentNode*>(node->_private);
> }
> 
> comments can be outside the root node too!

Yes. I wonder if Document should inherit from Node, for API at least, if not
for implementation.

> > I have also thought about removing the add_ methods() becauase the 
> > set_() methods do the same thing 90% of the time. The add_ 
> methods are 
> > only useful if you want to add more than one text or 
> comment node. I 
> > suppose that's slightly useful.
> 
> I think we should keep add_ in addition to set_ because a 
> node can have a child node list containing more than one text 
> contents node. What if I am able to implement my derived DOM 
> such that in my derived SAX parser I can add entity 
> references to the DOM I am building? I then need to be able 
> to add_text(), add_entity_reference(), and add_text(), e.g. 

Well, they are just convenience methods, but yes, that does seem to be the
point of them. We'll have to make sure that we do this consistently and
properly document the difference between set() and get().

Murray Cumming
www.murrayc.com
murrayc usa net




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]