1

I want to automatically generate an xml file for every record found in an xml column in a table.

Is there a script using a cursor or another method to do that?

1 Answer 1

0

You should be able to do this with xmlstarlet and a little scripting. I don't have a good xml file to run this against but this should do it, more or less. Should output all matching elements to tempfile.txt and then splits out the elements into output1.xml and counts up until all elements have been saved into their own xml files.

sourceFile=$1
xmlstarlet sel -t -c "/your/element" $sourceFile -n -o "splithere" > tempfile.txt
fileNumber=0
cat tempfile.txt | while read line; do
    if [[ $line == splithere ]]
    then
        let fileNumber++
        break
    fi
    echo $line >> output$fileNumber.xml
    done
rm -f tempfile.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .