Solved

Generating XML file.

Posted on 2013-06-19
7
356 Views
Last Modified: 2013-06-20
Hi,

I have 16 files each with different name and different content that database out put it at the end of each day which inside that is only account numbers (id)

386596
234567
454321
388596
236567
457321

Open in new window


and then I have another 16 files which is ready made xml with somewhat following code:

<script name="test_CURRENTDATE"  OnError="no" Errors="50000" TotalErrors="50000">
   <command>
      <operation name="inadvantage/CPSSmafbatch.CPS">
      </operation>
      <inputdata>
         <format type="bin"/>
         <data>
                          <inline><![TA[
=Se|ID|DAS


"1-1-386596"|"staticalue"
"1-1-234567"|"staticalue"
"1-1-454321"|"staticalue"
"1-1-388596"|"staticalue"
"1-1-236567"|"staticalue"
"1-1-457321"|"staticalue"



]]></inline>
         </data>
      </inputdata>
      <outputdata>
         <format type="bin"/>
         <file url="test_currentdate.log"/>
      </outputdata>
   </command>
</script>

Open in new window



in this code 1-1-386596"|"staticalue" where it's BOLD is always static for each have different static values which is ready and each dynamic where the account is have different file.

and also where you see test_currentdate.log and test_CURRENTDATE where it says current date I want to print todays date.

I would like to create 16 xml files as above and put the account numbers automatically can you guys help me to create something like this in php or JAVA. or shell

thanks for your time
0
Comment
Question by:hi4ppl
  • 3
  • 3
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39259051
is powersehll ok?
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39259145
It's certainly possible to do this in PHP, but the description makes it a little hard to understand exactly what you want to achieve.  I'll show you how to do this using HEREDOC notation.  If it's not enough of an answer, please post back and we can clarify the inputs and outputs.

Please see http://www.laprbass.com/RAY_temp_hi4ppl.php

<?php // RAY_temp_hi4ppl.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');


// THIS ARRAY MIGHT BE CREATED WITH http://php.net/file
$nums = array
( '386596'
, '234567'
, '454321'
, '388596'
, '236567'
, '457321'
);


// THIS IS TODAY'S DATE
$now = date('Y-m-d');


// MERGE THE ARRAY VALUES INTO THE TEMPLATE STRINGS
$str = NULL;
foreach ($nums as $num)
{
    $str .= '"1-1-' . $num . '"|"staticalue"' . PHP_EOL;
}


// THIS IS THE XML TEMPLATE USING VARIABLE SUBSTUTION
$xml = <<<EOD
<script name="$now"  OnError="no" Errors="50000" TotalErrors="50000">
   <command>
      <operation name="inadvantage/CPSSmafbatch.CPS">
      </operation>
      <inputdata>
         <format type="bin"/>
         <data>
                          <inline><![TA[
=Se|ID|DAS


$str


]]></inline>
         </data>
      </inputdata>
      <outputdata>
         <format type="bin"/>
         <file url="$now.log"/>
      </outputdata>
   </command>
</script>
EOD;


// SHOW THE WORK PRODUCT
echo '<pre>' . PHP_EOL;
echo htmlentities($xml);

Open in new window

Best regards, ~Ray
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 39259595
Hi, thanks this is seems okay, but as I said there is two things I want to clear here I think it's was not cleared while I describe it.

1- $nums = array value of this is in text file how to read text file and put account in this array. there is 16 files for this also

acount1.txt
acount2.txt
....
account16.txt

2-  where I mentioned "staticalue"  there is 16 files  which have 15 static values for each record in array. i.e

staticalue1
staticalue2
staticalue2
....
staticalue16


so my goal is:

that it grab numbers from each account.txt and put int in that array and then grab that particular static value and print it beside each account as this is now.

this files does the job except reading accounts from a file and place it in array, but the other thing I describe that it should do 16 files with different static value and different account file.

one way I think to have 16 PHP files but what im saying if this is possible to do it with one single files all these reading and placing the account and grab the Right static value.

thanks for time and help.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39260044
To read a file into an array use file(). You will find one array element for each line in the file.

To read several files, one after another, put the file names into an array and iterate over the array with foreach().

You can reuse the HEREDOC blocks inside the loop created by foreach.

Since I do not have your test data, I cannot provide you with a working example that reads multiple files.  I would suggest you try getting the foreach() loop to work first.  You will be able to use var_dump() to see that your script can find the names of the files.  Once you're sure of that part, then you can add the step that reads the contents of the files into an array.  Next you can add in the HEREDOC block to create the XML documents.

You can write XML documents into the file system with file_put_contents().
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 39262057
Hi thanks for the help, when I use file(location of file);
but it gives me result like bellow:

"1-1-header
"|"staticalue"
"1-1-5003191
"|"staticalue"
"1-1-5003699
"|"staticalue"
"1-5007900
"|"staticalue"
"1-1-5025775
"|"staticalue"
"1-5028194
"|"staticalue

where as I Want result like bellow:

"1-1-5003191"|"staticalue"
"1-1-5003699"|"staticalue"
"1-1-5007900"|"staticalue"
"1-1-5025775"|"staticalue"
"1-1-5028194"|"staticalue

and also one more thing how can I escape one filed from the file which is the header of the column of text, as you can see at first output it printed the header also but in real I want to escape it.

thanks for help
0
 
LVL 1

Author Closing Comment

by:hi4ppl
ID: 39262165
Thanks I fixed the print now it's okay thanks for help appreciate it
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39262226
Thanks for the points, ~Ray
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question