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

Re: parsing xml file using LIBXML

by dakkar (Hermit)
on May 12, 2005 at 12:57 UTC ( #456369=note: print w/ replies, xml ) Need Help??


in reply to parsing xml file using LIBXML

Various points to make...

  • as mirod says, that's an ugly piece of XML. But that's not the problem we're here to solve today...
  • getElementsByTagName works only on a Document object, not on any element: it finds all the elements with the given name anywhere in the document. I don't think that's what you need.
  • to do the match, you could use getAttribute() to get the value of the use attribute, and then use a regexp or something similar to test if it contains the value passed from the command line. Like:
    $attrValue =~ /\Q$param\E/
    where the \Q...\E is to avoid strange characters from being interpreted by the regexp engine.
  • learn XPath. Really do. That whole program can be reduced to a single XPath query. And it would be easier to read.
-- 
        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)


Comment on Re: parsing xml file using LIBXML
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2014-10-02 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (65 votes), past polls