what is CDATA?

what is CDATA?

por jeff ciaccio -
Número de respostas: 5

I am trying to create an Excel file that will generate the proper XML code. I am using Excel 2000, and it does not seem to like the macros that others have created in 2003 and beyond.


I am getting the following error: Parsing questions from import file.

Error importing question Invalid xml file - string expected (use CDATA?)


Here is my xml:


<?xml version="1.0" encoding="UTF-8"?>

<quiz>

<question type='shortanswer'> <name><text>KBr</name></text> <questiontext format 'html'><text>If potassium and bromine combine to form an ionic compound, what is the result of that reaction? To enter a subscript, use sub.<br>For example Li<sub>2</sub>O is entered Lisub2O</text></questiontext> <generalfeedback>Be sure to look up the value of each of the ion's charge and criss-cross if they do not add to zero.</generalfeedback> <defaultgrade>1</defaultgrade> <penalty>0.1</penalty> <hidden>0 </hidden> <shuffleanswers>0</shuffleanswers> <usecase>1</usecase> <answer fraction="100>" <text>KBr</text> <feedback><text>Correct, it is KBr!</text></feedback></answer> </question>

</quiz>

Any suggestions?

Em resposta a 'jeff ciaccio'

Re: what is CDATA?

por Itamar Tzadok -
There is a quote problem in

<answer fraction="100>"

In the Excel you may need to escape apostrophes

each of the ion\'s charge and

Here is an example of how CDATA may look like:

="<question type='multichoice'><name><text><![CDATA["&L25&"]]></text></name><questiontext format='html'><text><![CDATA["&M25&"]]></text></questiontext><penalty>0</penalty><hidden>0</hidden><shuffleanswers>1</shuffleanswers><single>true</single>"

Hope this helps. sorriso
Em resposta a 'jeff ciaccio'

Re: what is CDATA?

por Matt Bury -
Foto de Plugin developers
Hi Itamar,

To answer your question, CDATA is an XML tag that allows you to include special characters that would otherwise get parsed by any XML reading software. Special characters are things like =,",\,{}, etc.

For example, the following tag in an XML file would play havoc with an XML parser if it weren't in a CDATA tag:

this="that" myemail@mailbox.com {a:100 b:200 c:300 d:400} \'escape\' \n etc.

I hope this answers your question.

All the best,

Matt
Em resposta a 'Matt Bury'

Re: what is CDATA?

por jeff ciaccio -
Thanks guys! I thought I had changed all of my double quotes to single, but I guess this slipped past me.
Em resposta a 'jeff ciaccio'

Re: what is CDATA?

por Kristin Dougherty -

I know this message is a little late but I came across this website that is very helpful for when you are using apostrophe's and quotes, etc.

http://www.tedmontgomery.com/tutorial/htmlchrc.html

The problem I have now is I can't get Moodle to bulk upload questions that I want to be bold.. i have tried the following codes and get the same error as you had...

<b>  </b>

<strong>    </strong>

<span style="font-weight: bold;">      </span>

Em resposta a 'jeff ciaccio'

Re: what is CDATA?

por Howard Miller -
Foto de Core developers Foto de Documentation writers Foto de Particularly helpful Moodlers Foto de Peer reviewers Foto de Plugin developers
This answer is even later, but just for the record some of the answers have missed the point.

You can't have HTML buried inside the XML. It will break the XML and that's why the OP is getting the error. The point is that if you want to include arbitrary HTML between the 'text' tags then you need to include it in a CDATA section. CDATA escapes all that is within it, forcing it to be interpreted as simple text not XML markup.

See http://en.wikipedia.org/wiki/CDATA

See Moodle_XML_format for an example.