PDA

View Full Version : QDomDocument & OS Crash on doc.createElementNS



patrik08
19th June 2006, 13:14
Why this crash ...?

is an other method to debug?





QString Gui_Tidy::Createtag(QString inputfile,QString set_lang)
{
QString inside="File not found!";
qDebug() << "### open file " << inputfile;
QFile file(inputfile);
if (file.exists()) {
qDebug() << "### file found ok " << inputfile;
if (file.open(QFile::ReadOnly | QFile::Text)) {
inside =file.readAll();
file.close();
}
}
QDomDocument doc("shghshsh");
QDomElement root = doc.createElement("root");
doc.createElementNS("http://www.pulitzer.ch/2005/shop/shema/1.0/","s");
doc.createElementNS("http://www.pulitzer.ch/2005/PuliCMS/1.0","cms");
doc.appendChild(root);
QDomElement page = doc.createElementNS("http://www.pulitzer.ch/2005/PuliCMS/1.0","page");
root.appendChild(page);
QDomElement e;
QDomAttr language = e.attributeNode("la");
language.setValue(set_lang);
page.setAttributeNodeNS(language);
QDomText t = doc.createTextNode(inside); /* filter self text? */
page.appendChild(t);
QString xml = doc.toString();
qDebug() << "### xml result " << xml;
return xml;
}

e8johan
19th June 2006, 13:58
Have you tried doing a stack-trace using a debugger? Is doc NULL?

jpn
19th June 2006, 14:01
Why this crash ...?

is an other method to debug?

Maybe this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-usage-of-the-debugger-1833.html/?highlight=debugger) helps.


// createElementNS() returns the newly created element,
// following 2 lines have no point at all..
doc.createElementNS("http://www.pulitzer.ch/2005/shop/shema/1.0/","s");
doc.createElementNS("http://www.pulitzer.ch/2005/PuliCMS/1.0","cms");

// you initialize an empty (null) element and then ask for it's "la" attribute?
QDomElement e;
QDomAttr language = e.attributeNode("la");
language.setValue(set_lang);
page.setAttributeNodeNS(language);
// i guess it should be more like this (instead of those 4 wicked lines)
// page.setAttribute("la", set_lang);

[/QUOTE]

patrik08
19th June 2006, 18:13
So is running but xml is no utf8 ..... or no unicode....

i like text on xml file so on server cms.... (i tested tidy or qt4 asci and textstream codec)

I have a php function "utf8_to_unicode" but is not possibel to run on qt4 ....

original function unicode xml files ... http://ppk.ciz.ch/format/qt/Multi_Language.phps

http://ppk.ciz.ch/format/qt/unicote_text.png
Is not possibel to post this text on forum.... on post rewrites....

The reusult on the cms i can write any language.... this is text from image...


提契诺州的美味佳肴具有意大利风格,同时具有自己的独特之处。纯正的本地风味可以在这个地区特 有的"trattorie", "grotti"(客栈)或是餐馆中享用,它们都是流行的聚会场所,最初却是冬季出售葡萄酒和熟食的小店。

提契诺葡萄酒中的极品无疑当数源自法国波尔多地区的墨尔乐红葡萄酒。自19世纪初开始从法国引进这种葡萄酒 以取代当地葡萄酒以来,墨尔乐葡萄酒就适应了提契诺州的气候,并在这里取得了辉煌的成功。






QString Gui_Tidy::Createtag(QString inputfile,QString set_lang)
{
QString inside="File not found!";
qDebug() << "### open file " << inputfile;
QFile file(inputfile);
if (file.exists()) {
qDebug() << "### file found ok " << inputfile;
if (file.open(QFile::ReadOnly | QFile::Text)) {
inside =file.readAll();
file.close();
}
}
QDomDocument doc("");
QDomElement root = doc.createElement("root");
root.setAttribute("xmlns:s","http://www.pulitzer.ch/2005/shop/shema/1.0/");
root.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
doc.appendChild(root);
QDomElement page = doc.createElement("cms:page");
page.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
page.setAttribute("la",set_lang);
QDomText t = doc.createTextNode(inside);
page.appendChild(t);
root.appendChild(page);
QString xml = doc.toString();
QByteArray ilmiofile = xml.toAscii();
qDebug() << "### xml result " << ilmiofile.data();
return ilmiofile.data();
}


Only this qt function transorm a xml utf8 ... but on qtextedit show normal iso....


bool Gui_Tidy::file_put_contents_utf8(QString fullFileName,QString xml)
{
QTextCodec *codecutf8 = QTextCodec::codecForMib(106);
/*QTextCodec *codeclatin1 = QTextCodec::codecForMib(4);*/

QString data = xml+"\n";
QFile f( fullFileName );
if ( f.open( QFile::WriteOnly | QFile::Text ) )
{
QTextStream sw( &f );
sw.setCodec(codecutf8);
sw << data;
f.close();
return true;
}
return false;
}