Re: libxml2 application data
"Tod Harter" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
I rather disagree with you on the basic concept that 'that isn't the primary purpose of ID'... Certainly having an id attribute does not guarantee any particular association with anything in memory, but that actually is irrelevant, what needs to be done is to IDENTIFY particular nodes (IE to associate extra data with them). Sure, XML can be well-formed and contain duplicate ids, but that would still be at best poor practice, and there is a whole laundry list of similar problems a document can have. So realistically, assuming he wants to identify elements, which I would consider to be pretty likely, then assigning them IDs will work fine. Those elements requiring extra data can be given an id and a hash of id to additional properties will work fine. Depending on the use case you can either quickly look up the actual element with a DOM call, or use a bit more elaborate data structure and hold a reference to it. Building your hash to start with is a perl one-liner using '//@id' (though you may well be able to use a more efficient expression). Given the information in the OP it is certainly a perfectly good suggestion. May not solve his problem, but it also may. On Mon, Dec 22, 2008 at 10:13 AM, Robin Berjon <[email protected]> wrote: > On Dec 22, 2008, at 15:21 , Tod Harter wrote: > >> Uh, isn't that the purpose of the 'id' attribute of an element? >> > > No. The identity of an element and whatever allows you to refer to one of > its nodes in memory are two completely orthogonal concepts. Using the ID can > have any number of issues, e.g. loading the same tree twice but annotating > differently, duplicate IDs in the tree (not valid, but still perfectly > well-formed XML), or calling cloneNode on an element that has an ID. Note > that it also only applies to elements (the OP said nodes). If the use case > is constrained enough it could work, but it certainly isn't the primary > purpose of ID. > > > -- > Robin Berjon - http://berjon.com/ > Feel like hiring me? Go to http://robineko.com/ > > > > > > -- The Wise adapts himself to the world. The Fool adapts the world to himself. Therefore, all progress depends on the Fool. _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs