I've written two scripts with XML::Simple and XML::DOM to do some replacements they work but with XML::Simple I have a problem with the output being alphabetically sorted which I've read is a limitation. I'm now trying to do the same with XML::Twig but can't seem to figure out how to do it. I've displayed the XML and the Simple code so you can get a better understanding of what I want to achieve. I'm wanting to change the Id= part from Id="/Local/ App/App1" to Id=/App1"

XML snip:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <Profile xmlns="xxxxxxxxx" name="" version="1.1" xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance"> <Application Name="App1" Id="/Local/App/App1" Services="1" pol +icy="" StartApp="" Bal="5" sessInt="500" WaterMark="1.0"/> <AppProfileGuid>586e3456dt</AppProfileGuid> </Profile>
XML Simple Code
use XML::Simple; my $xml = new XML::Simple (ForceArray => 1, KeepRoot => 1,KeyAttr=>[]) +; my $data = $xml->XMLin($xmlfile); my $Id = $data->{Profile}->[0]->{Application}->[0]->{Id}; my $CsID = (split(/\//, $Id))[-1]; $data->{Profile}->[0]->{Application}->[0]->{Id} = $CsID; print $xml->XMLout($data);

In reply to XML::Twig Text replacement by Gizmo

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.