Escaped quotes in xml


#1

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;
}

output:


<?xml version="1.0" encoding="UTF-8"?>
<TEST foo="bar">
  <SUB>&quot;hello world&quot;</SUB>
</TEST>

#2

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 :)


#3

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>

#4

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?


#5

The term CDATA is used about

 


#6

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.


#7

I was actually replying to olilarkin, not to Guillaume.

But re: CDATA, I'm not opposed to doing that, but am not sure how it could easily be added without bloating the XmlElement class.


#8

Thank you to Rebbur. It express exactly what I wanted dir. Sorry for my english


#9

i'm just interested in making my application's file format as human readable as possible, and not bloating it with gazillions of "&quot;"s . i thought there might be a way.


#10


#11

Understood, and yes, it could probably be done - bit of a low priority for me, but happy to accept change suggestions if you want to have a go!