Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: XML: how to change the values of specific tags

by idsfa (Vicar)
on Apr 19, 2006 at 17:35 UTC ( #544417=note: print w/ replies, xml ) Need Help??


in reply to XML: how to change the values of specific tags

XML::Simple will read in and write out your XML file. If you want to change the data, you need to search through the data hash it provides and make the changes yourself. OTOH, this is a trivial XSL transformation for something like XML::XSLT:

# # Here's the stylesheet. The annoying part is that the # actual change is three lines, the rest is grammar. You # can add multiple templates to make simultaneous changes. # my $xsl = <<EOS; <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" versi +on="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <transform> <xsl:apply-templates/> </transform> </xsl:template> <xsl:template match="//time"> $new_time </xsl:template> </xsl:stylesheet> EOS # # The perl is down here # use XML::XSLT; my $xslt = XML::XSLT->new ($xsl, warnings => 1); $xslt->transform ($xmlfile); print $xslt->toString; $xslt->dispose();

This same tool could also answer your question in how to replace the <anon> tag (XML::Simple).


The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon


Comment on Re: XML: how to change the values of specific tags
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-08-28 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls