Results 1 to 12 of 12

Thread: QDomImplementation real dom Document;

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDomImplementation real dom Document;

    i wand to write xml doc on QDomDocument not entyti ....

    on line to line the doc is so:
    Qt Code:
    1. xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    2. xml.append("<cms:root xmlns:cms=\"http://www.pulitzer.ch/2005/PuliCMS/1.0\">");
    3. xml.append("<cms:page la=\"it\">");
    4. xml.append(desc_it->GetXMLTag());
    5. xml.append("</cms:page>");
    6. xml.append("</cms:root>");
    7. QString stayutf8 = xml.join("\n");
    8. qDebug() << "### xml result1 " << stayutf8;
    To copy to clipboard, switch view to plain text mode 

    and on a real QDomDocument.... Manual say so:

    Qt Code:
    1. QDomDocument doc(QDomImplementation::createDocument(QString("http://www.pulitzer.ch/2005/PuliCMS/1.0/"),
    2. QString("utf8"),(const QDomDocumentType)"xml"));
    3. QDomElement root = doc.createElement("root");
    4. root.setAttribute("xmlns:s","http://www.pulitzer.ch/2005/shop/shema/1.0/");
    5. root.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
    6. doc.appendChild(root);
    7. QDomElement page = doc.createElement("cms:page");
    8. page.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
    9. page.setAttribute("la","it");
    10. page.appendChild((const QDomDocumentFragment)(desc_it->GetXMLTag()));
    11. root.appendChild(page);
    12. QString xml = doc.toString();
    13. qDebug() << "### xml result2 " << xml;
    To copy to clipboard, switch view to plain text mode 

    on php5 and qt all dom function is same but new domdocument no....

    php = $dom = new DOMDocument('1.0', 'utf-8') and become a clean first line...

    qt no why?

    how to become a clean line <?xml version=\"1.0\" encoding=\"utf-8\"?> so tidy xml dont clean?
    Last edited by jacek; 23rd June 2006 at 15:33. Reason: code changed, so it doesn't break the page layout

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by patrik08
    on php5 and qt all dom function is same but new domdocument no....

    php = $dom = new DOMDocument('1.0', 'utf-8') and become a clean first line...

    qt no why?
    Because DOM Level 2 specification does not specify the constructor of Document (since it's an interface, not a class).

    Quote Originally Posted by patrik08
    how to become a clean line <?xml version=\"1.0\" encoding=\"utf-8\"?> so tidy xml dont clean?
    As usual in Qt --- with only a few lines of code:
    Qt Code:
    1. #include <QDomDocument>
    2.  
    3. #include <QtDebug>
    4.  
    5. int main()
    6. {
    7.  
    8. QDomProcessingInstruction header = doc.createProcessingInstruction( "xml", "version=\"1.0\"" );
    9. doc.appendChild( header );
    10.  
    11. QDomElement root = doc.createElement( "test" );
    12. doc.appendChild( root );
    13.  
    14. qDebug() << doc.toString();
    15.  
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 
    $ ./xml
    "<?xml version="1.0"?>
    <test/>
    "
    Last edited by jacek; 23rd June 2006 at 19:24.

  3. The following user says thank you to jacek for this useful post:

    patrik08 (23rd June 2006)

  4. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    and QDomDocumentFragment so helpfull is the same?

    Qt Code:
    1. QDomElement page = doc.createElement("cms:page");
    2. page.setAttribute("xmlns:cms","http://www.pulitzer.ch/2005/PuliCMS/1.0/");
    3. page.setAttribute("la","it");
    4. page.appendChild((const QDomDocumentFragment)(desc_it->GetXMLTag()));
    5. root.appendChild(page);
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by patrik08
    and QDomDocumentFragment so helpfull is the same?
    I'm not sure what you mean.

    Quote Originally Posted by patrik08
    (const QDomDocumentFragment)(desc_it->GetXMLTag())
    What does GetXMLTag() return? It seems that you are doing something dangerous here.

  6. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by jacek
    I'm not sure what you mean.


    What does GetXMLTag() return? It seems that you are doing something dangerous here.

    Fragments of xml return.... tree or only </nocode>
    I wand to attach piece of fragment to other... to build on file...

    Is a imb db2 to -> mysql transfer file and back 2MB adress rysinc...

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by patrik08
    Fragments of xml return....
    If that method returns QDomDocumentFragment, then why do you need a cast?

  8. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by jacek
    If that method returns QDomDocumentFragment, then why do you need a cast?

    why? is a existing file ... trasformed to qstring and replace <? xml...>

    wenn i open the file on QDomDocument ... on error.... i must return a empyty dom?
    on qstring on error read i return a <nullnode/> qstring...
    qt code
    Qt Code:
    1. if(!xmlfile.open( QIODevice::ReadOnly ) ) {
    2. out....
    3. }
    4. QString errorStr;
    5. int errorLine;
    6. int errorColumn;
    7.  
    8. QDomDocument doc("http://www.pulitzer.ch/2005/PuliCMS/1.0");
    9. if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {
    10. QString error = (QString("Parse error at line %1, column %2:\n%3")
    11. .arg(errorLine)
    12. .arg(errorColumn)
    13. .arg(errorStr) );
    14. ErrorConfig(error);
    15. xmlfile.close();
    16. }
    To copy to clipboard, switch view to plain text mode 

    the best way i think to make a similar php class on qt...

    php code
    php Code:
    1. /* Aggregate moore xml file to one or insert xml fragment */
    2.  
    3. class XML extends DOMDocument {
    4. function __construct () {
    5. parent::__construct ();
    6. }
    7. function __destruct() {
    8. parent::__destruct();
    9. }
    10. /* function similar from createDocumentFragment but enter xml file or pure xml frags */
    11. function appendXML_or_File($node,$frag) {
    12.  
    13. if (is_file($frag)) {
    14. $frag = @file_get_contents($frag);
    15. }
    16. $tmpdoc = new self('1.0', 'utf-8');
    17. $tmpdoc->loadXML("<dummyroot>".$this->Remove_Version($frag)."</dummyroot>")
    18. or Error_Manager::msg('Error on fragment not possibel to insert xml Fragment!'.htmlentities($frag, ENT_QUOTES),__FILE__,__LINE__);
    19. $newnode = $node->ownerDocument->importNode($tmpdoc->documentElement,true);
    20. $child = $newnode->firstChild;
    21. while ($child) {
    22. $nextChild = $child->nextSibling;
    23. $node->appendChild($child);
    24. $child = $nextChild;
    25. }
    26. }
    27. /* remove php code or xml header ..... */
    28. function Remove_Version($string) {
    29. return preg_replace_callback("/(<\?php|<\?)(.*?)\?>/si",create_function("","return '';"),$string);
    30. }
    31. function utf($string) {
    32. return Multi_Language::utf8_to_unicode($string);
    33. }
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 

    but can i open qtextstreams on dom?

    Qt Code:
    1. if (! doc.setContent(qtextstreams...) ) {
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 24th June 2006 at 17:04. Reason: code changed, so it doesn't break the page layout

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by patrik08
    why? is a existing file ... trasformed to qstring and replace <? xml...>
    I was asking about this:
    (const QDomDocumentFragment)(desc_it->GetXMLTag())
    Either you don't need it or you do something Bad.

    Quote Originally Posted by patrik08
    but can i open qtextstreams on dom?
    Not directly, but you can try:
    Qt Code:
    1. doc.setContent( stream.readAll() );
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomDocumentFragment is not !isDocumentFragment()

    The fragment is not fragment!

    Qtextstream "<samplenode/>" readAll() return a false QDomDocument

    and fragment give a false isDocumentFragment() why?


    Qt Code:
    1. #include <QtDebug>
    2. #include <QDebug>
    3. #include <QObject>
    4. #include <QSettings>
    5. #include <QErrorMessage>
    6. #include <QProcess>
    7. #include <QDomDocument>
    8. #include <QDomElement>
    9. #include <QStringList>
    10. #include <QDir>
    11. #include <QDomDocumentFragment>
    12. #include <QDomImplementation>
    13. #include <QMessageBox>
    14.  
    15. int main(int argc, char *argv[]) {
    16.  
    17. QDomDocument dom_external;
    18. QString filexmleternal = "./qtpage.xml";
    19. bool is_fi = false;
    20.  
    21. QFile xmlfile(filexmleternal);
    22. if(!xmlfile.open( QIODevice::ReadOnly ) ) {
    23. /* stay false ! */
    24. }
    25. if (dom_external.setContent(&xmlfile)) {
    26. is_fi = true;
    27. }
    28. if (!is_fi) {
    29. qDebug() << "External file not loadet!";
    30. } else {
    31. qDebug() << "External file is super!! loadet!";
    32. frag.appendChild(dom_external);
    33. if (!frag.isDocumentFragment()) {
    34. qDebug() << "Is not a fragment !!!";
    35. }
    36. }
    37.  
    38. /* external file end */
    39. /* new qdom to insert external ... */
    40. QDomProcessingInstruction header = doc.createProcessingInstruction( "xml", "version=\"1.0\"" );
    41. doc.appendChild( header );
    42. QDomElement root = doc.createElement( "root" );
    43. doc.appendChild( root );
    44. QDomElement big = doc.createElement( "big" );
    45. if (is_fi) {
    46. //////big.appendChild(frag); /* not insert */
    47. }
    48. root.appendChild( big );
    49. /////QDomNode::isDocumentFragment ()
    50. qDebug() << doc.toString();
    51. return 0;
    52. };
    To copy to clipboard, switch view to plain text mode 

    pro file...
    Qt Code:
    1. TEMPLATE = app console
    2. TARGET +=
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. win32:debug { CONFIG = console }
    7. CONFIG += qt warn_on release
    8. QT += xml
    9.  
    10. # Input
    11. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocumentFragment is not !isDocumentFragment()

    Quote Originally Posted by patrik08
    fragment give a false isDocumentFragment() why?
    Probably it's a bug, use QDomDocument::createDocumentFragment() to create document fragments.

    PS. If you post code, please, post only relevant part. 3/4 of your example has nothing to do with QDomDocumentFragment.

  12. #11
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomImplementation real dom Document;

    is solved so.... and fragment not run!

    make a node from external root and .toElement(); after big.appendChild(extase);
    to other node....


    Qt Code:
    1. int main(int argc, char *argv[]) {
    2.  
    3. QDomDocument dom_external;
    4. QString filexmleternal = "./qtpage.xml";
    5. bool is_fi = false;
    6.  
    7. QFile xmlfile(filexmleternal);
    8. if(!xmlfile.open( QIODevice::ReadOnly ) ) {
    9. /* stay false ! */
    10. }
    11. is_fi = dom_external.setContent(&xmlfile);
    12. QDomElement root_extern = dom_external.documentElement();
    13. QDomNode externxml = root_extern.firstChild();
    14. QDomNode externxml_2 = dom_external.importNode(externxml,true);
    15. QDomElement extase = externxml_2.toElement();
    16.  
    17. if (!is_fi) {
    18. qDebug() << "External file not loadet!";
    19. } else {
    20. qDebug() << "External file is super!! loadet!";
    21. }
    22.  
    23. QDomProcessingInstruction header = doc.createProcessingInstruction( "xml", "version=\"1.0\"" );
    24. doc.appendChild( header );
    25. QDomElement root = doc.createElement( "root" );
    26. doc.appendChild( root );
    27. QDomElement big = doc.createElement( "big" );
    28. big.appendChild(extase); /* the external file not from fragment */
    29. root.appendChild( big );
    30.  
    31.  
    32.  
    33. qDebug() << doc.toString();
    34. return 0;
    35. };
    To copy to clipboard, switch view to plain text mode 

  13. #12
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomImplementation real dom Document;

    Quote Originally Posted by jacek View Post
    Because DOM Level 2 specification does not specify the constructor of Document (since it's an interface, not a class).


    As usual in Qt --- with only a few lines of code:
    Qt Code:
    1. #include <QDomDocument>
    2.  
    3. #include <QtDebug>
    4.  
    5. int main()
    6. {
    7.  
    8. QDomProcessingInstruction header = doc.createProcessingInstruction( "xml", "version=\"1.0\"" );
    9. doc.appendChild( header );
    10.  
    11. QDomElement root = doc.createElement( "test" );
    12. doc.appendChild( root );
    13.  
    14. qDebug() << doc.toString();
    15.  
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Thanks, this helps me!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.