Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

xmlstarlet sel -t -c "/your/element" $sourceFile -n -o "splithere" > tempfile.txt
cat tempfile.txt | while read line; do
    if [[ $line == splithere ]]
        let fileNumber++
    echo $line >> output$fileNumber.xml
rm -f tempfile.txt
share|improve this answer

Your Answer


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.