Re: libxml2 application data
Robin Berjon <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
On Dec 22, 2008, at 18:40 , Tod Harter wrote:
> 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).
The primary purpose of ID is to identify an element (not a general
node) in a document (not in a representation of it). There is a number
of cases in which the two overlap, but conflating the two is confusing.
> Sure, XML can be well-formed and contain duplicate ids, but that
> would still be at best poor practice
Of course it's bad practice, but real-world data is broken and full of
bad practices. Unless you can ascertain ID-validity, then introducing
IDs as a solution when it's not needed opens your flanks to the risks
associated with 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).
Using @id is also something that's likely to fail unless you have
prior knowledge of what you're processing.
> Given the information in the OP it is certainly a perfectly good
> suggestion. May not solve his problem, but it also may.
As I said in my previous post, if you constrain the problem enough
such that only elements are considered, you can reliably recognise
IDs, you can modify your document to add IDs where they don't exists,
and you can guarantee that they are all unique, then sure it can work.
But we don't know that, hence my friendly waving of the warning flag
in case the OP rushes to implement that and hits a wall.
--
Robin Berjon - http://berjon.com/
Feel like hiring me? Go to http://robineko.com/
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs