Re: What would you like to see in XML::LibXML ?
Aaron Crane <[email protected]> Thu, 2 Feb 2012 11:48:13 +0000
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <CACmk_ttGp4d1A0WGqM-512DCJ1SruZa+nWuXuWwySUVma3TbWw@mail.gmail.com> |
Michael Ludwig <[email protected]> wrote: > Aaron Crane schrieb am 29.01.2012 um 14:49 (+0000): >> I'd particularly value the ability to annotate a node with a Perl >> scalar, and retrieve that scalar later > > Interesting idea. Could you briefly explain what such annotations are > good for? Or share a pointer? A somewhat glib answer is that you could use them in exactly the same ways that libxml2 allows C-language callers to use the _private field in the node structure. (For that matter, I assume that's precisely why libxml2 provides it.) More specifically, one use I've had is determining whether a given node in a document-like XML instance represents "phrasing" content. The sense in which I'm using that term is borrowed with light modifications from HTML5: certain elements are candidates for phrasing content (like <em> and <strong> in HTML, and unlike <p> or <li>), but an element node with non-phrasing descendants should never be considered phrasing. I'm glossing over some subtleties here, of course; for example, text nodes are phrasing, unless they're ignorable whitespace. Now, it's easy enough to write a function that takes a node, and tells you whether it's phrasing in this sense. But that can require non-trivial amounts of computation — more than would be desirable in an inner loop, in some applications. However, since this function would be pure (in that only changing the document can change the answer), it can be straightforwardly cached — as long as you've got somewhere sane to store the answer. Currently, the only way to cache data like that with XML::LibXML is to use attributes in an element node, and find an attribute name that wouldn't otherwise have any effect. Being able to annotate non-element nodes would help in some circumstances, and being able to use extra-DOM data would help in others. -- Aaron Crane ** http://aaroncrane.co.uk/ _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs