Generating XML file.

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
LVL 1
hi4pplAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
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
 
Meir RivkinFull stack Software EngineerCommented:
is powersehll ok?
0
 
hi4pplAuthor Commented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Ray PaseurCommented:
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
 
hi4pplAuthor Commented:
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
 
hi4pplAuthor Commented:
Thanks I fixed the print now it's okay thanks for help appreciate it
0
 
Ray PaseurCommented:
Thanks for the points, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.