27Loco
6th July 2010, 14:24
Heho,
I have a problem with the QXmlStreamWriter class. When using UTF-16 encoding garbage characters will appear in my XML document.
QXmlStreamWriter xml;
xml.setDevice(&file);
// here is the problem
xml.setCodec(QTextCodec::codecForName("utf16"));
xml.setAutoFormatting(true);
xml.setAutoFormattingIndent(2);
xml.writeStartDocument();
xml.writeDTD("<!DOCTYPE backup>");
xml.writeStartElement("Backup");
xml.writeAttribute("version", "1.0");
xml.writeStartElement("Task");
xml.writeAttribute("name", "MyName");
xml.writeTextElement("Description", "My short description");
xml.writeEndElement(); // Task
xml.writeEndElement();
xml.writeEndDocument();
Output:
<?xml version="1.0" encoding="UTF-16"?>à¨ã°€â„€ä€ä¼€äŒ€å€ ¤€å€€ä”€â€‚æˆ€æ„€æŒ æ¬€ç”€ç€€ã¸€à´€
<Backup version="1.0">à¨â€‚ 㰀å€æ„€çŒ 欀 渀愀洀攀㴠€âˆ€ä´€ç¤€â€‚æ˜€æ¤€çˆ €çŒ€ç€â€‚æˆ€æ„€æŒ€æ €ç”€ç€€âˆ€ã¸€à´€
<Description>My short description</Description>à¨â€‚â€‚â€‚â€‚ã°€ä” €æ¸€æ„€æˆ€æ°€æ”€æ€ã €ç€çˆ€ç”€æ”€ã°€â¼€ä ”€æ¸€æ„€æˆ€æ°€æ”€æ€ 㸀ഀ
etc....
Do you have any idea? Thank you very much for your help.
Best regards,
Loco
I have a problem with the QXmlStreamWriter class. When using UTF-16 encoding garbage characters will appear in my XML document.
QXmlStreamWriter xml;
xml.setDevice(&file);
// here is the problem
xml.setCodec(QTextCodec::codecForName("utf16"));
xml.setAutoFormatting(true);
xml.setAutoFormattingIndent(2);
xml.writeStartDocument();
xml.writeDTD("<!DOCTYPE backup>");
xml.writeStartElement("Backup");
xml.writeAttribute("version", "1.0");
xml.writeStartElement("Task");
xml.writeAttribute("name", "MyName");
xml.writeTextElement("Description", "My short description");
xml.writeEndElement(); // Task
xml.writeEndElement();
xml.writeEndDocument();
Output:
<?xml version="1.0" encoding="UTF-16"?>à¨ã°€â„€ä€ä¼€äŒ€å€ ¤€å€€ä”€â€‚æˆ€æ„€æŒ æ¬€ç”€ç€€ã¸€à´€
<Backup version="1.0">à¨â€‚ 㰀å€æ„€çŒ 欀 渀愀洀攀㴠€âˆ€ä´€ç¤€â€‚æ˜€æ¤€çˆ €çŒ€ç€â€‚æˆ€æ„€æŒ€æ €ç”€ç€€âˆ€ã¸€à´€
<Description>My short description</Description>à¨â€‚â€‚â€‚â€‚ã°€ä” €æ¸€æ„€æˆ€æ°€æ”€æ€ã €ç€çˆ€ç”€æ”€ã°€â¼€ä ”€æ¸€æ„€æˆ€æ°€æ”€æ€ 㸀ഀ
etc....
Do you have any idea? Thank you very much for your help.
Best regards,
Loco