Wednesday, April 13, 2022

[SOLVED] wanted to use results of find command in custom script that i am building

Issue

I want to validate my XML's for well-formed ness, but some of my files are not having a single root (which is fine as per business req eg. <ri>...</ri><ri>..</ri> is valid xml in my context) , xmlwf can do this, but it flags out a file if it's not having single root, So wanted to build a custom script which internally uses xmlwf, my custom script should do below,

iterate through list of files passed as input (eg. sample.xml or s*.xml or *.xml) for each file prepare a temporary file as <A>+contents of file+</A> and call xmlwf on that temp file, Can some one help on this?


Solution

You could add text to the beginning and end of the file using cat and bash, so that your file has a root added to it for validation purposes.

cat <(echo '<root>') sample.xml <(echo '</root>') | xmlwf

This way you don't need to write temporary files out.



Answered By - Adam B
Answer Checked By - Dawn Plyler (WPSolving Volunteer)