Re: [Libxmlplusplus-general] parametrizing libxml++ for the character /string type



Le Lundi 27 Janvier 2003 20:58, Stefan Seefeld a écrit :
> hi there,
>
> libxml2 uses some internal utf8 types to represent characters.
> libxml++ currently uses std::string, which only works for characters
> in the ASCII subset of utf8. It was suggested to use glibmm::ustring
> instead, but I'd like to propose a different solution:
>
<big snip>
>
> Hope this makes some sense to you.
>

A lot of. But the change you suggest in the way _TextNode would be implemented 
is big : at this time, the libxml2 types (xmlNode in this case) are used only 
are read/write time, not to store the datas while manipulating nodes.

But I like much the idea so I see two options :
- doing exactly the way you did, but this means rethink completely the way 
Node is implemented
- Keep the idea of a templated class, but with no parent class, and 
string_type as the content type.

template <typename string_type, typename string_traits>
class TextNode
{
public:
   void set_content(const string_type &content)
   {
      _TextNode::set_content(string_traits::to_utf8(content));
   }

   void write(xmlDocPtr doc, xmlNodePtr parent) const;
private:
   string_type content;
};

Then the write() member function would use the string adaptor to produce the 
libxml2 node.

void TextNode::write(xmlDocPtr doc, xmlNodePtr parent) const
{
  xmlNodePtr node = xmlNewText( string_traits::to_utf8(_content) );
/* ... */
}

The read method would do the exact oposite.
This way we wouldn't have to modify too much the current implementation, 
unless we decide that it's better to rely on libxml2 types to store datas.


Thanks for your suggestion,

Christophe






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