Results 1 to 12 of 12

Thread: QDomImplementation real dom Document;

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 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 16:04. 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
    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 

  3. #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: 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 

  4. #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: 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.

  5. #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;

    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 

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.