How to get same input xml file as xml out file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiranbk
    New Member
    • Jan 2015
    • 1

    How to get same input xml file as xml out file

    i am trying to update xml element value using XML::Simple::XM Lin .But when I am again trying to retrive the XML data as it was before using XML::Simple::XM Lout.
    But finding a deviation in the format can any pls help me out with same xml file structure.

    input file:
    Code:
    <NavigationMap> <PageLink> <LinkText/> <url>/ae/index.html</url> <Domain>//www.fedex.com</Domain> <Protocol>UnSecure</Protocol> <Target/> <LinkParams/> </PageLink> <ImageSource alt="FedEx Home">//images.fedex.com/images/c/t1/gh/logo-header-fedex-express.png</ImageSource> </Logo> </NavigationMap>
    Output file after execute:
    Code:
    <NavigationMap lastId="146"> <Logo> <ImageSource alt="FedEx Home">//images.fedex.com/images/c/t1/gh/logo-header-fedex-express.png</ImageSource> <PageLink> <Domain>//www.fedex.com</Domain> <LinkParams></LinkParams> <LinkText></LinkText> <Protocol>UnSecure</Protocol> <Target></Target> <url>/zw/index.html</url> </PageLink> </Logo> </NavigationMap>
    Perl code:
    Code:
    $data = $xml -> parse_file($file_in,ForceArray => 1,KeyAttr =>[]);
    foreach $TabEle (@{$data->{Logo}}) # retrieving list of values under Tab element
    {
    		foreach $NameEle (@{$TabEle->{PageLink}}){
    		foreach $LinktxtEle(@{$NameEle->{Protocol}}){
    		print $LinktxtEle;
    		}
    		
       }
     }
    XMLout($data,rootname => 'NavigationMap',KeyAttr =>[],OutputFile => $file_in,NoSort => 1);	#Writing xml back with updated value.
    }
    Expected result:
    Code:
    <NavigationMap lastId="146"> <PageLink> <LinkText/> <url>/ae/index.html</url> <Domain>//www.fedex.com</Domain> <Protocol>UnSecure</Protocol> <Target/> <LinkParams/> </PageLink> <ImageSource alt="FedEx Home">//images.fedex.com/images/c/t1/gh/logo-header-fedex-express.png</ImageSource> </Logo> </NavigationMap>
    Last edited by RonB; Jan 14 '15, 02:31 PM. Reason: Added code tags
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    The author of the module states:
    STATUS OF THIS MODULE

    The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.

    The major problems with this module are the large number of options and the arbitrary ways in which these options interact - often with unexpected results.

    Patches with bug fixes and documentation fixes are welcome, but new features are unlikely to be added.

    Comment

    Working...