i'm storing a var as json which then becomes an xml element. I have noticed that in the XML any quotation marks are escaped with """. As far as i can tell it shouldn't be nessecary.
Am i wrong? is there a way to prevent the escaped quotations marks. Below is a test prog and the output.
thanks
oli
test main.cpp:
int main (int argc, char* argv[])
{
ScopedPointer<XmlElement> e = new XmlElement ("TEST");
e->setAttribute ("foo", "bar");
var varThings = "hello world";
XmlElement* things = new XmlElement ("SUB");
things->addTextElement (JSON::toString(varThings, false));
e->addChildElement(things);
e->writeToFile(File("~/test.xml"), String::empty);
return 0;
}
They may not be strictly necessary, but it is legal XML.. If you wanted to make sure by checking the XML spec as to whether there really can be a quote there, and suggest a code change to avoid it, I'd be open to the idea :)
I also encountered the same "problem".
I would save the javacript in my xml.
One solution would be to use a section "CDATA" but does XmlDocument class manages the reading and not writing.
Do you have a solution?
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
]]>
</script>
TBH I'm unclear about why you're even flagging this as a problem? The juce code produces legal XML, and any compliant parser should deal with it correctly, right?
I think he means that when you want to store a Javascript you might run into issues regarding characters that mess up the xml parsing. So he suggest using a CDATA section for storing Javascript for instance. The XMlDocument seems to support CDATA when parsing but not when writing, so i guess he wants to know if you would want to support adding a CDATA section to an XMLElement.
i'm just interested in making my application's file format as human readable as possible, and not bloating it with gazillions of """s . i thought there might be a way.