Solved

Generating XML file.

Posted on 2013-06-19
7
353 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 108

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

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 108

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now