Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

XML::Twig TwigHandler for attributes?

by Anonymous Monk
on Sep 10, 2002 at 18:54 UTC ( [id://196783]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to some XML parsing, and after taking a look at some of the available modules I really like XML::Twig`s interface best.

My problem is that I want to set up some TwigHandlers for attributes instead of elements (so the handler sub is passed the current twig/element the attribute was found in).
But after searching the XML::Twig documentation and tutorial I didn't find a suitable way to do this. Have I overlooked anything or is it simply impossible? Or might there be a good work-around?

Replies are listed 'Best First'.
Re: XML::Twig TwigHandler for attributes?
by PodMaster (Abbot) on Sep 11, 2002 at 00:51 UTC
    I'm just going to quote the pod, mmkay (don't got perl handy). It looks like you're looking for "attribute_condition" :
    new
    twig_handlers
    This argument replaces the corresponding XML::Parser argument. It consists of a hash { expression => \&handler} where expression is a generic_attribute_condition, string_condition, an attribute_condition,full_path, a partial_path, a gi, _default_ or <_all_>.

    The idea is to support a usefull but efficient (thus limited) subset of XPATH. A fuller expression set will be supported in the future, as users ask for more and as I manage to implement it efficiently. This will never encompass all of XPATH due to the streaming nature of parsing (no lookahead after the element end tag).

    A generic_attribute_condition is a condition on an attribute, in the form *[@att=``val''] or *[@att], simple quotes can be used instead of double quotes and the leading '*' is actually optional. No matter what the gi of the element is, the handler will be triggered either if the attribute has the specified value or if it just exists.

    An attribute_condition is a simple condition of an attribute of the current element in the form gi[@att=``val''] (simple quotes can be used instead of double quotes, you can escape quotes either). If several attribute_condition are true the same element all the handlers can be called in turn (in the order in which they were first defined). If the =``val'' part is ommited ( the condition is then gi[@att]) then the handler is triggered if the attribute actually exists for the element, no matter what it's value is.

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-28 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found