XML : Converting text to xml file

I need help or script in php.

I want to have a textarea in my site where if me or some user inputs some text it should be converted to xml file.

Actually I am using a plugin in Wordpress, in which i can import data using an xml file which needs to have a very specific format

Just as an example of what would be inputted in a textarea

  what is the colour of the sea ?  blue  red  orange  purple  black  blue=correct    Question 2  ans1  ans2  ans3  ans4  ans5  ans3=correct  .  list goes on    

Expected output xml file would look like

  <data>  <questionText>What is the color of the sea?</questionText>  <answers>  <answer points="1" correct="true">  <answerText>blue</answerText>  </answer>  <answer points="1" correct="false">  <answerText>red</answerText>  </answer>  <answer points="1" correct="false">  <answerText>orange</answerText>  </answer>  <answer points="1" correct="false">  <answerText>purple</answerText>  </answer>  <answer points="1" correct="false">  <answerText>black</answerText>  </answer>  </answers>  <questionText>Question 2?</questionText>  <answers>  <answer points="1" correct="false">  <answerText>ans1</answerText>  </answer>  <answer points="1" correct="false">  <answerText>ans2</answerText>  </answer>  <answer points="1" correct="true">  <answerText>ans3</answerText>  </answer>  <answer points="1" correct="false">  <answerText>ans4</answerText>  </answer>  <answer points="1" correct="false">  <answerText>ans5</answerText>  </answer>  </answers>  </data>    

Any help is greatly appreciated. I am not a pro at coding and have very less knowledge of it. The code would be used for personal use only and would not be used for any financial benefits.

No comments:

Post a Comment