Results 1 to 5 of 5

Thread: Filling multiple XML files from an XLS file

  1. #1
    Join Date
    Nov 2009
    Posts
    47

    Filling multiple XML files from an XLS file

    I have a recurring task to do and I have 2 hours to 20 times that spot. I seek a scripted solution.

    Here:
    I have approximately 340 XML files to create and nurture with data contained in an excel file.

    My excel file containing 4 columns, respectively:

    the Computer Name, the LogonName the FullName and a string that is logonName_RDP.

    My XML file (copied below) must be completed as follows:

    Code:
    <configuration xmlns="http://xml.juniper.net/ive-sa/6.3R6.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <users>
     <user-roles>
      <user-role>
       <name>FullNAME</name>  
                <general>
                    <overview>
         <options>
                            <vlan-source-ip>false</vlan-source-ip>
                            <session-options>false</session-options>
                            <ui-options>false</ui-options>
                        </options>
         <access-features>
                            <web>false</web>
                            <windows-files>false</windows-files>
                            <nfs-files>false</nfs-files>
                            <sam>false</sam>
                            <telnet-ssh>false</telnet-ssh>
                            <terminal-services>true</terminal-services>
                            <meeting>false</meeting>
                            <email>false</email>
                            <network-connect>false</network-connect>
                        </access-features>
        </overview>
       </general>
       <terminal-services>
        <sessions>
         <session>
          <name>FullNAME_RDP</name>  
          <description />  
          <parent>--none--</parent>  
          <auto-launch>true</auto-launch>  
          <wts>
           <username>&lt;USER&gt;</username>  
           <password-type>variable</password-type>  
           <variable-password>&lt;PASSWORD&gt;</variable-password>  
           <host>COMPUTER NAME</host>  
           <client-port>0</client-port>  
           <server-port>3389</server-port>  
           <screen-size>fullscreen</screen-size>  
           <color-depth>16-bit</color-depth>  
           <launch-seamless>false</launch-seamless>  
           <alias-name />  
           <application-path />  
           <path-dir />  
           <connect-drives>false</connect-drives>  
           <connect-printers>false</connect-printers>  
           <connect-comports>false</connect-comports>  
           <allow-clipboard>false</allow-clipboard>  
           <experience-options>
            <desktop-background>false</desktop-background>  
            <menu-window-animation>false</menu-window-animation>  
            <bitmap-caching>false</bitmap-caching>  
            <desktop-composition>false</desktop-composition>  
            <show-content-dragging>false</show-content-dragging>  
            <themes>false</themes>  
            <font-smoothing>false</font-smoothing>  
           </experience-options>
           <connect-smartcards>false</connect-smartcards>  
           <sound-options>disable</sound-options>  
          </wts>
         </session>
        </sessions>
       </terminal-services>
      </user-role>
     </user-roles>
     <user-realms>
      <realm>
       <name>basic</name>
       <role-mapping-rules>
                    <rule>
                        <name>logonName</name>
                        <user-name>
                            <test>is</test>
                            <user-names>logonName</user-names>
                        </user-name>
                        <roles>FullNAME</roles>
                        <stop-rules-processing>false</stop-rules-processing>
                    </rule>
       </role-mapping-rules>
      </realm>
     </user-realms>
    </users>  
    </configuration>
    Can you help me? Do you have the miracle solution?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Filling multiple XML files from an XLS file

    sed and awk are your friends. You register your input file in CSV, then you do it as:

    Code:
        awk -F\; '{print "sed -e \"s/Computer Name/$1/\" -e \"s/LogonName/$2/\" -e \"s/FullName/$3/\" -e \"s/logonName_RDP/$4/\" input.csv > $1_$2_$3_$4.xml"}' > treatment.sh
         
        . ./treatment.sh

  3. #3
    Join Date
    Nov 2009
    Posts
    47

    Re: Filling multiple XML files from an XLS file

    Your solution interests me, but how do I do to recover the structure of my original XML? Because in fact the xml generated are intended to be injected into a gateway juniper. Is there possibility to specify another xml file "model" in order to resume input (output) the same structure as the xml template? I do not know if it is very clear that I say but I do not know how to explain otherwise.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Filling multiple XML files from an XLS file

    I think I understood, there was an error in what I put above. It should be better something like this:

    Code:
    awk -F\; '{print "sed -e \"s/Computer Name/$1/\" -e \"s/LogonName/$2/\" -e \"s/FullName/$3/\" -e \"s/logonName_RDP/$4/\" template.xml > $1_$2_$3_$4.xml"}' input.csv > treatment.sh

  5. #5
    Join Date
    Nov 2009
    Posts
    47

    Re: Filling multiple XML files from an XLS file

    Thank you for your response. Nevertheless it remains an obscure little thing for my brain. If I understand the tags in my XML template I must put the names of fields (computer Nam Logon ...) to replace my variables ($ 1 $ 2 $ 3 ...)? Should the separators are of my csv "\"? And I will generate awk script treatment.sh who will do the trick? If that's your solution its brilliant!

Similar Threads

  1. Replies: 3
    Last Post: 22-05-2012, 05:32 PM
  2. Replies: 3
    Last Post: 23-06-2010, 02:57 AM
  3. Error when filling up my configuration files to set up Nagios
    By Jagadamba15 in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 09:47 AM
  4. batch file to split multiple text files in half.
    By yammyguy in forum Windows Server Help
    Replies: 8
    Last Post: 11-05-2009, 06:19 PM
  5. Merge multiple PDF files in single PDF file
    By Steinbach in forum Tips & Tweaks
    Replies: 2
    Last Post: 19-03-2009, 11:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,723,579.37853 seconds with 17 queries