Re: [Libxmlplusplus-general] API questions



On Wed, 2003-01-22 at 16:50, Stefan Seefeld wrote:
> hi there,
> 
> I'm currently looking into existing C++ wrappers
> for libxml2. I'v written one myself, as a Quick Hack (tm),
> but would like to get rid of that and rather contribute
> to an existing one and focus on the stuff I'd actually do
> with that library...
> 
> One thing I do a lot right now with xml documents is reading
> them in (DOM), then searching for specific data. I do this
> with xpath expressions, so I need a way to retrieve a 'NodeSet'
> from a document, given an xpath.

Note that I have never used xpath.

> What is needed for this is 1) a document to search in, 2) a
> context node, 3) the actual xpath expression.
> 
> Would you be interested into a patch that adds
> such functionality ?

Absolutely.

> You currently don't have a 'Document' class (though the
> 'DomParser' comes close), and the 'Node' class doesn't
> know the document it is part of.
> 
> The simplest change would be an added 'lookup' method in
> the DomParser:
> 
> typedef std::vector<Node *> NodeSet; // pointers or deep copies ?

We use pointers everywhere else at the moment.

> NodeSet DomParser::lookup(const Node *context,
>                            const std::string &xpath) const;
> 
> Though there are a couple of 'issues':
> 
> 1) I really think I'm not searching in a parser, but in a
>     document (a DOM tree, actually), though it's the DomParser
>     that creates it (factory).

Feel free to patch to create the Document abstraction.

> 2) For various reasons I think nodes should hold a reference to
>     the document they are part of. This is important as soon as
>     you want to interpret them, for example namespaces can only
>     looked up in the document, the same is true for default attributes
>     (defined in the dtd).
>     Assuming the node knows its document, the above 'lookup' method
>     could be written more naturally as

If this is necessary then it sounds OK, though there might be some
circular-reference complications.

>     'NodeSet Node::lookup(const std::string &) const;'

Yes, that looks nicer.

> Another question I have is about the supported character domain.
> You currently use std::string, but it is obvious that this isn't
> enough, at least not if you want to provide a generic XML API.
> I read in a message about using glibmm. What's the background for
> this ? What functionality do you need from there ? Why wouldn't
> a simple replacement of std::string by std::wstring suffice ? The
> actual unicode processing isn't the scope of libxml++, or is it ?

UTF8 has variable numbers of bytes per character, so wstring is no good:
http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch03s04.html
-- 
Murray Cumming
murray usa net
www.murrayc.com





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