Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.