Git Product home page Git Product logo

xml_to_perl_and_back's Introduction

       This small program shows the way to manage arrays and values at given XML file.
       That way doesn't keep order for XML node sequences.

   CLI using
           $./xmlrw.pl xmlrw.xml >new_xmlrw.xml
           $./xmlrw.pl xmlrw.xml -d >new_xmlrw.txt
           $./xmlrw.pl new_xmlrw.txt >one_more_xmlrw.xml
           $diff -uN new_xmlrw.xml one_more_xmlrw.xml

   Perl programming
           use Storable qw(dclone);
           use File::Temp;
           use Data::Dumper; $Data::Dumper::Sortkeys = 1; # To make Dump file comparable
                             $Data::Dumper::Purity   = 1; # To make Dump evaluating
           use XML::Simple;

           # Create object
           $doc = XMLin( 'xmlrw.xml', forcearray => 1 );

           # Get some node value
           $some_value = $doc->{CstmrCdtTrfInitn}[0]->{GrpHdr}[0]->{InitgPty}[0]->{Nm}[0];

           # Create deep copy of XML node
           my $branch      = $doc->{CstmrCdtTrfInitn}[0]->{GrpHdr}[0]->{InitgPty};
           my $src_node    = $branch->[0];
           my $target_node = dclone($src_node);

           # Insert new node into the same branch
           push @{$branch}, $target_node;

           # Modify value of new node
           $branch->[1]->{Nm}[0] = $some_value . ' new!';

           # Remove some nodes
           my $index_of_first_deleted_node = 0;    # That is first(old) node
           my $how_much                    = 1;    # Only one node
           splice( @{$branch}, $index_of_first_deleted_node, $how_much );

           # Print new XML
           print xmlOut($doc);

xml_to_perl_and_back's People

Contributors

wws22 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.