I’m writing an application where I create an XML document that I can either save to disk or send to a webservice. The document needs to have ISO-8859-1 as the encoding and using XMLLib as the XML parser I’ve gotten the save to disk part working perfectly. The problem is when I’m gonna send it to webservice as I then send the XML data as a string, and the command in XMLLib for returning an XML object as a string (XMLDisplayXML) ignores the specified encoding and always uses UTF-8. I tried using do shell script: cat as the string producer instead but it cannot handle certain characters and prints them as questionmarks. (The same characters that force me to use ISO-8859-1 to begin with.) I also tried XML Tools which seems like it should work, but no matter what I do it just won’t generate the string I want.
set temp_path to ((path to startup disk) as text) & "temp.xml"
set theXML to parse XML alias temp_path encoding "ISO-8859-1"
(*temp.xml already has the correct encoding but for some reason XML Tools doesn't recognize it. The "encoding" parameter is supposed to set the encoding to whatever I specify regardless of this, however.*)
set xmldata to generate XML theXML with including XML declaration
It’s the xmldata string that I send to the webservice. Anyway, for some reason the encoding part doesn’t get included. I tried a more complicated code:
set temp_path to ((path to startup disk) as text) & "temp.xml"
set theXML to parse XML alias temp_path
set tempxmldata to generate XML theXML without including XML declaration
set theXML to {XML encoding:"ISO-8859-1", XML tag:tempxmldata}
set xmldata to generate XML theXML with including XML declaration
Which does everything correctly apart from adding </> to the outside of the string. That is, it generates:
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<
datagoeshere
moredatagoeshere
etc. etc.
[b]/>[/b]"
When it should generate the same thing without the (by me) bolded characters.
Any help? The only thing I need to do is to generate XML data as a string while having the encoding of my choice (ISO-8859-1). It really shouldn’t be this troublesome.