Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
use strict; use warnings; use XML::LibXML 2; use XML::LibXML::PrettyPrint; my $xml = XML::LibXML::->load_xml(string => <<'INPUT'); <?xml version="1.0" encoding="UTF-8"?> <response> <result name="response" numFound="58582" start="0"> <doc> <str name="body">Have a great time at this park!</str> <int name="is_park_id">317851</int> <str name="ss_image_thumb_small"/> <str name="title">Playground</str> </doc> </result> </response> INPUT my %changes = ( '//response' => sub { $_->setNodeName('Fe +ed') }, '//result' => sub { $_->setNodeName('Pr +oducts'), %$_ = (); }, '//doc' => sub { $_->setNodeName('Pr +oduct'), %$_ = (); }, '//str[@name="body"]' => sub { $_->setNodeName('De +scription'), %$_ = (); }, '//int[@name="is_park_id"]' => sub { $_->setNodeName('Ex +ternalId'), %$_ = (); }, '//str[@name="ss_image_thumb_small"]' => sub { $_->setNodeName('Im +ageUrl'), %$_ = (); }, '//str[@name="title"]' => sub { $_->setNodeName('Na +me'), %$_ = (); }, ); while (my ($xpath, $processor) = each %changes) { $xml->findnodes($xpath)->foreach($processor); } print( XML::LibXML::PrettyPrint:: -> new(element => { compact => [qw/ Description ExternalId ImageUrl Name /], }) -> pretty_print($xml) -> toString );
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Perl - Modify the nested XML tags by tobyink
in thread Perl - Modify the nested XML tags by Murari

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 surveying the Monastery: (5)
As of 2024-03-29 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found