View previous topic :: View next topic
|
Author |
Message |
PL1user
New User
Joined: 26 Nov 2008 Posts: 13 Location: UK
|
|
|
|
Hi
I am working on a requirement where I need to deal with XML files. The XML file need to be formatted to a specific format before I start processing it.
For Example, if my file looks like this,
A
B
AAAAAAAAAAAA
/B
B
BBBBBBBBBBBB
/B
/A
I want this file to be formatted as,
A/A
B/B
AAAAAAAAAAAA
B/B
BBBBBBBBBBBB
I have to append '/A' to the first record where 'A' is present.
I have to append the first '/B' with the first 'B' & the second 'B' with the second '/B'
Is there a way I can do this using DFSORT ? Any ideas would be really helpful. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Sorry, but your "rules" are not clear. You need to do a better job of explaining them. Are 'A' and 'B' actual values or do they just represent some other values? Maybe a more extensive and/or realistic example would help. |
|
Back to top |
|
|
PL1user
New User
Joined: 26 Nov 2008 Posts: 13 Location: UK
|
|
|
|
<XMLFile>
<SetOne>
<Name>XYZ</Name><Country>UK</Country>
</SetOne>
<SetTwo>
<Name>ABC</Name><Country>INDIA</Country>
</SetTwo>
</XMLFile>
This needs to be formatted as,
<XMLFile></XMLFile>
<SetOne></SetOne>
<Name>XYZ</Name><Country>UK</Country>
<SetTwo></SetTwo>
<Name>ABC</Name><Country>INDIA</Country>
Basically I want the start and end tag to be on the same record. If you note the above example, in cases where the end tags are not on the same record, I am extracting the end tag and appending it to the start tag.
Please let me know if I am not clear.
Thanks. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
You can use a DFSORT job like the following to do what you asked for:
Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
<XMLFile>
<SetOne>
<Name>XYZ</Name><Country>UK</Country>
</SetOne>
<SetTwo>
<Name>ABC</Name><Country>INDIA</Country>
</SetTwo>
</XMLFile>
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OMIT COND=(1,2,CH,EQ,C'</')
OUTFIL IFTHEN=(WHEN=(1,80,SS,NE,C'/'),
OVERLAY=(31:C'</',2,20,1:1,80,SQZ=(SHIFT=LEFT)))
/*
|
|
|
Back to top |
|
|
PL1user
New User
Joined: 26 Nov 2008 Posts: 13 Location: UK
|
|
|
|
<XMLFILE>
<SETONE>
<NAME>XYZ</NAME><COUNTRY>UK</COUNTRY>
</SETONE>
<SETTWO>
<NAME>ABC</NAME><COUNTRY>INDIA</COUNTRY>
</SETTWO>
</XMLFILE>
Thanks a lot Frank. But there is one more condition which I should have put this on my earlier post. Your code would just stick a </SETONE> or </SETTWO> or </XMLFILE> when there is no '</' in the entire record.
But lets suppose my file is like this,
<XMLFILE>
<SETONE>
<NAME>XYZ</NAME><COUNTRY>UK</COUNTRY>
<SETTWO>
<NAME>ABC</NAME><COUNTRY>INDIA</COUNTRY>
</SETTWO>
</XMLFILE>
There is a <SETONE> but no </SETONE>. In this case, I should not blindly write a </SETONE>. I should be abending.Can you please suggest how this can be handled ? Thankyou |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
It sounds like you need to define the "rules" for your error checking and implement them with a program. I don't know how much error checking you want to do, what you would consider to be an error, or if "abending" means issuing a particular error message or just terminating with any old message. To get that kind of control usually requires writing a program with the needed logic. |
|
Back to top |
|
|
|