2 Replies Latest reply on Aug 10, 2010 7:15 AM by adobeMurat

    Extract and save xml nodes to filesystem

    tgsoft

      Hi All,

       

      I am looking for great ideas for the best way to extract xml nodes from a complete xml-file and save each to a given path in the filesystem, with filename incremented for each file... file1,2,3,4.

       

      I have a process in workbench that takes an xml file as input (complete XML shown below). In the complete solution I will have an unknown number of child nodes to save.

       

      Complete XML file with two records. Is in a process variable "xmlComplete" - type=xml:

      ==================

      <archiveIndexRecords>
           <indexRec>
                <i1>7173</i1>
                <i2>1405781111</i2>
                <i3>71709999999</i3>
           </indexRec>
           <indexRec>
                <i1>6226</i1>
                <i2>1405782222</i2>
                <i3>71708888888</i3>
           </indexRec>
      </archiveIndexRecords>

       

      Want to save each child record (<indexRec>) to the filesystem. Lets say to C:\temp\records\file1.xml   (..2.xml etc) and with content like this.

      <indexRec>
           <i1>7173</i1>
           <i2>1405781111</i2>
           <i3>71709999999</i3>
      </indexRec>

      ...

       

      What kind of solution would you advice?? An execute script with loop or a loop of setValue steps??

      Hope for great input. feel free to ask for more info if needed, Thanks

       

      Yours,

      Thomas Groenbaek

        • 1. Re: Extract and save xml nodes to filesystem
          $Nith$ Level 4

          Your requirement is much easy to implement with simple activities such as SetValue, WriteXML etc.

           

          I prefer not to use Execute Script activity for this simple logic.

           

          Nith

          • 2. Re: Extract and save xml nodes to filesystem
            adobeMurat Level 1

            Hi,

            You need to create a loop in your process on workbench. First count nodes and set it to an integer variable.

             

            /process_data/@number = count(/process_data/xmlComplete/archiveIndexRecords/indexRec)

             

            Then you need to get first node's data to write to disk.

             

            /process_data/FirstNode = /process_data/xmlComplete/archiveIndexRecords/indexRec[number(/process_data/@i)] (i is another integer variable which is 1 as default. )

             

            When you get first node's data set it to a document variable and write down to disk. Then add 1 to i variable and control it with number (count of nodes) variable. Decide for next record or not.

             

            You can find an example how to create loops in workbench link below.

             

            http://muratkuru.com.tr/?p=106

             

            Murat

             

            www.muratkuru.com.tr