paulami_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I wanted to add some more attributes in an element tag in an existing xml. Following is the existing xml.

<Codeline codeline-name="NW_11_COR"> <Patch-attributes CR-Number="012006153200021828702013" project-n +ame="bc.uwl" SCV-name="UWL COLL PROCESS ENGINE" SP-Level="11" patch-l +evel="12" /> <Patch-attributes CR-Number="012006153200021828702013" project-n +ame="bc" SCV-name=" COLL PROCESS ENGINE" SP-Level="11" patch-level="0 +"/> <Patch-attributes CR-Number="012006153200035553682013" project-n +ame="coll.room" SCV-name="KMC COLLABORATION" SP-Level="11" patch-leve +l="6" /> </Codeline>

This is how it should look after editing i.e each patch attribute element should have two new atrributes added namely do-name and changelist

<Codeline codeline-name="NW_11_COR"> <Patch-attributes CR-Number="012006153200021828702013" project-n +ame="bc.uwl" SCV-name="UWL COLL PROCESS ENGINE" SP-Level="11" patch-l +evel="12" DO-name="UWLJWF11P" Changelist="159103" /> <Patch-attributes CR-Number="012006153200021828702013" project-n +ame="bc" SCV-name=" COLL PROCESS ENGINE" SP-Level="11" patch-level="0 +" DO-name="UWLJWF11" Changelist="159103" /> <Patch-attributes CR-Number="012006153200035553682013" project-n +ame="coll.room" SCV-name="KMC COLLABORATION" SP-Level="11" patch-leve +l="6" DO-name="KMCCOLL11P" Changelist="160317" />

Thanks.

Replies are listed 'Best First'.
Re: adding some more attributes in an existing xml using perl
by choroba (Cardinal) on Nov 05, 2013 at 14:36 UTC
    Using XML::XSH2, a wrapper around XML::LibXML:
    open 1061307.xml ; for /Codeline/Patch-attributes { set @DO-name "UWLJWF11P" ; set @Changelist "159103" ; } save :b ;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: adding some more attributes in an existing xml using perl
by ww (Archbishop) on Nov 05, 2013 at 16:56 UTC
    ... and you have tried WHAT?

    This is not code-a-matic. The Monastery exists to help you learn; not to write your code for you.

Re: adding some more attributes in an existing xml using perl
by Anonymous Monk on Nov 05, 2013 at 18:36 UTC