We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, as the title suggest, i'm having an issue when i try to save a xml file.
basically the problem is that when i try to save a xml file with the function "saveXML()" it changes some chars, for example, if a variable has the char "&" it gets changed with "& amp;".
Any idea on what is happening?
(Mod edit, broke the html entity so it's visible)
Answers
So & becomes & ?
https://forum.processing.org/two/discussion/11860/problems-with-aeoa-characters-in-xml
The forum / html is probably changing the & amp; in the post to an ampersand. (It was, I changed the question to make it visible)
The XML is doing the opposite - ampersands need escaping in XML.
koogs explained it better than me, thanks. I thought about encoding, how should i convert it?
i've tryed with that code (and changed the ISO-8859-1 with UTF-8) but didn't work (saving[][] is the variable where i have the string with those characters).
well, the "solution" that i found is the following, first i save the XML file, then i open it as an string array and search for things like "& amp;" "& lt;" "& gt;" (without the spaces) and i replace them with "&", "<" and ">" witch are special chars for the XML file, after all that i save the file, the code is the following:
i don't like this "solution" because i dont know if there is another special char that i have to consider. If someone have an eleganter solution it would be welcomed
if you save it as xml then load it as xml. the problem is that you're reading it back as strings.
I don't load it, the xml file has to be opened with another program that prints barcodes
It is possible that your barcode reader is broken, and cannot read valid XML.
HOWEVER, this is a valid XML file:
It lists a single value, "&". That value is correctly escaped.
This is an invalid, broken XML file:
It generates an error because it lists a broken entity.
Go ahead and try it!
and you will see that the second example fails validation:
If you leave the output of saveXML() alone, it will create correct, valid XML. If you mess with it by loading and saving strings as you describe it will break the XML character encoding.
(i've looked and the processing implementation of xml doesn't support cdata blocks)
@jeremydouglass you are right, it turns into a broken xml file, so it isn't a solution.
Great! So is just using
saveXML()
working for you, and does that mean your problem is resolved?