Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Handler communication in XML::Twig

by PodMaster (Abbot)
on Feb 12, 2004 at 17:56 UTC ( [id://328619]=note: print w/replies, xml ) Need Help??


in reply to Handler communication in XML::Twig

See "Private Attributes" in the XML::Twig docs.
Attributes with a name starting with # (illegal in XML) will not be output, so you can safely use them to store temporary values during processing.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Handler communication in XML::Twig
by diotalevi (Canon) on Feb 12, 2004 at 18:13 UTC
    I saw that but don't think it is meant for this sort of problem. That requires that I write into some "other" scratch area of the document currently being parsed. I'd do this in an obfu but not for production code.
Re: Re: Handler communication in XML::Twig
by mirod (Canon) on Feb 12, 2004 at 18:16 UTC

    Note that you can store anything in a private attribute, not just text, it's just a regular Perl variable, so an array ref is perfectly OK. (note to self, add this to the docs... done ;--)

      This is just an FYI but I didn't get the sense from the documentation that this was something to be used as a shared scratchpad. On re-reading it just now it occurs to me that I don't know what the private attribute is supposed to be written to or what its lifetime is.

        The "private" attributes are just like regular attributes, they can be accessed just like regular ones, they are just not output. So they live with the element they are attached to, and disappear when it does, either when the whole twig element goes out of scope or when the element is deleted/purged or flushed.

        I usually use private attributes to store information that is attached to a part of the tree, what you call a scratchpad I guess. But I have also used it to store data for the whole document, as an "official" way to store attributes in the OO sense. This way I know that even if the author changed the underlying implementation of the twig this method would still be valid ;--)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://328619]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found