I would like to write all the output, including errors of a Shell script I wrote in XML format.
I noticed there are XML modules for PERL to do this. Are Unix shell scripts capable of creating XML documents, without having to resort to using echo "<tag> ${field} </tag>" ??
Currently, I have in my Unix shell script, a series of echo commands, carefully placed so that a valid XML document is produced, regardless if the script completes or fails due to an error.
Here is a sample:
dump() {
log "<env>"
logxml "WORKINGDIR" ${WORKINGDIR}
logxml "CSVHOME" ${CSVHOME}
logxml "XMLHOME" ${XMLHOME}
logxml "OUTPUTHOME" ${OUTPUTHOME}
logxml "LIBPATH" ${LIBPATH}
logxml "CLASSPATH" ${CLASSPATH}
log "</env>"
}
where log=echo and logxml is a function which encloses the 2nd parameter in a tag, whose name is the 1st parameter.
<WORKINGDIR>
d:/workarea/test
</WORKINGDIR>
I manage to produce the log in XML format and it looks great, but the shell script looks ugly. It is riddled with echo commands all over the place.
Is combining XML and shell script a bad idea? Has someone come up with some sort of solution for this?