Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, I am trying to learn and use XML with perl but because of difficulty that I am having with the perldoc XML::Twig and also the website of twig(despite all the tutorials, I decide to seek for help here. honestly, I just don't think I am getting it.

Anyway, I have fairly complicated XML file I want to parse out so that I can do some report on it but I am just not sure how to use XML::Twig nor if XML::Twig is even the right module to use.

I have been
1)trying to read the doc but honestly, it's little bit over my head...
2)trying to follow the tutorials on the website but it's not giving me what I want..(i am sure I am just not getting it .. same for 1) as well but
3)also did super seach on perlmonks w/ following key words ---> xml twig and read pretty much read all posts)

I have wrote a example xml file below and my question is, if I wanted to make a array of id so that my @array will contain qw/ msn movies espn/ how would I go about doing it?

I was thinking somehow using first_child method?
Would appreciate the pointer/advise.
thank you
-------- code that I was just looking at------------- #!/usr/bin/perl use warnings; use strict; use XML::Twig; my $twig = XML::Twig->new(twig_roots => { one => 1}); $twig->parsefile(shift); $twig->print; --- example file ------- <config> <one id="msn" type="shopping"> <traffic> <daily value="on" /> <weekly value="off" /> <monthly value="off" /> </traffic> </one> <one id="movies" type="entertainment"> <traffic> <daily value="on" /> <weekly value="off /> <monthly value="on" /> </traffic> </one> <one id="espn" type="sports"> <traffic> <daily value="on" /> <weekly value="on" /> <monthly value="on /> <hyper value="true /> </traffic> </one> </config>

In reply to trying to understand xml::twig and also trying to learn how to extract attribute by convenientstore

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found