Results 1 to 20 of 21

Thread: QT4 DomXPath / DomElementContainer find tag.

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 QT4 DomXPath / DomElementContainer find tag.

    On QTextBrowser is not possibel to make a standard <a href=\"#\" target=\"xx\"> link...
    target will remove after reload text ...!

    So i search a iterate to handle this, my popup dialog link write a link so:
    http://www.qtcentre.org/#target=_blank
    After i rewrite this on php xml...

    Now i found DomElementContainer from http://blog.wysota.eu.org/

    i test so... und it can not find link... founf 0 . why wo i mistake?

    Qt Code:
    1. const char *xml = "<test><tag>content 1</tag><tag>co<a href=\"#test\" target=\"xx\">ntent</a> 2</tag> "
    2. "<othertag>wrongcontent</othertag>"
    3. "<tag>content 3</tag></test>";
    4.  
    5. int main(){
    6. doc.setContent(QString(xml));
    7. DomElementContainer c(doc, "a");
    8. int link = 0;
    9. foreach(QDomElement e, c) {
    10. link++;
    11. }
    12.  
    13. qDebug() << "### total link found -> " << link;
    14.  
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    on php i rewrite so....



    Qt Code:
    1. function Rewrite_QT_Tag($xhtml) {
    2. /* rewrite not support target on QTextedit tag <a> */
    3. /* samble : <a href="http://www.qtcentre.org/#target=_blank">
    4.   <span style=" text-decoration: underline; color:#0000ff;">QtCentre</span>
    5.   </a>*/
    6. $dom = new XML();
    7. $dom->loadXML($xhtml);
    8. $xp = new DomXPath($dom);
    9. $xp ->registerNamespace('default','http://www.w3.org/1999/xhtml');
    10. $result = $xp->query("//default:a");
    11. foreach ($result as $node) {
    12. $attuale = $node->getAttribute("href");
    13. /* get text from qt span and insert text node.... */
    14. $testodentro ="";
    15. while($node->hasChildNodes()) {
    16. /* get span text inside <a><span>text link</span></a>*/
    17. $testodentro .=$node->childNodes->item(0)->nodeValue;
    18. $node->removeChild($node->childNodes->item(0));
    19. }
    20. $testodentro = eregi_replace("\n"," ",$testodentro);
    21. $testo = $dom->createTextNode($testodentro);
    22. $node->appendChild($testo);
    23.  
    24. /* rewrite target */
    25. if (eregi("#target=",$attuale)) {
    26. $params = explode("#target=", $attuale);
    27. $urigo = $params[0];
    28. $node->setAttribute("href",$urigo);
    29. /**/
    30. if (eregi("^(http|https)+(:\/\/)+[a-z0-9_-]+\.+[a-z0-9_-]", $urigo )) {
    31. $node->setAttribute("target","_blank");
    32. $node->setAttribute("class","Link_External");
    33. } else if (eregi('mailto:',$urigo)) {
    34. $node->setAttribute("class","Link_Mail");
    35. } else {
    36. $node->setAttribute("target",$params[1]);
    37. $node->setAttribute("class","Link_Internal");
    38. }
    39. /**/
    40. } else if (eregi("^(http|https)+(:\/\/)+[a-z0-9_-]+\.+[a-z0-9_-]", $attuale )) {
    41.  
    42. $node->setAttribute("target","_blank");
    43. $node->setAttribute("class","Link_External");
    44. } else {
    45. continue;
    46. }
    47. }
    48. /* end link rewrite */
    49. $xhtml = $dom->saveXML();
    50. return $xhtml;
    51. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by patrik08 View Post
    On QTextBrowser is not possibel to make a standard <a href=\"#\" target=\"xx\"> link...
    target will remove after reload text ...!
    I think you must have done something wrong. Qt Assistant is based around QTextBrowser and it uses anchors for method and property names and that seems to work fine...

    Is this code you pasted in your post somehow relevant to the question?

    BTW. The container doesn't work for you, because it iterates direct children of the element which it was given and in the code you pasted "a" is a child of "tag", so you'd have to do:
    Qt Code:
    1. foreach(QDomElement elem, DomElementContainer(doc, "tag"))
    2. foreach(QDomElement subelem, DomElementContainer(elem, "a"))
    3. links++;
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 18th June 2007 at 18:00.

  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: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by wysota View Post
    I think you must have done something wrong. Qt Assistant is based around QTextBrowser and it uses anchors for method and property names and that seems to work fine...
    Yes on ready document read only its work ... My problem i have 3 case on QTextBrowser
    View modus / Edit modus Wysiwyg / Source edit modus /

    BTW. The container doesn't work for you, because it iterates direct children of the element which it was given and in the code you pasted "a" is a child of "tag", so you'd have to do:
    Qt Code:
    1. foreach(QDomElement elem, DomElementContainer(doc, "tag"))
    2. foreach(QDomElement subelem, DomElementContainer(elem, "a"))
    3. links++;
    To copy to clipboard, switch view to plain text mode 
    Is here a way to make this container Xpath similar?
    like:
    /body/p[0]/a/span

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by patrik08 View Post
    Yes on ready document read only its work ... My problem i have 3 case on QTextBrowser
    View modus / Edit modus Wysiwyg / Source edit modus /
    Still I don't see a problem. Especially given a fact that QTextBrowser is read-only, so you're surely not using it for modes other than "view".

    Is here a way to make this container Xpath similar?
    like:
    /body/p[0]/a/span
    If you implement an XPath parser, then I don't see a problem. I don't need such complicated things. My most common use of XML trees is iterating over subtrees, so such a simple container is enough.

  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: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by wysota View Post
    Still I don't see a problem. Especially given a fact that QTextBrowser is read-only, so you're surely not using it for modes other than "view".
    QTextBrowser -> QTextEdit
    WysiwygText->setReadOnly(false);

    People edit text and view
    http://www.qt-apps.org/content/show....?content=59493

    and work..

    Qt Code:
    1. void Base_Edit::ModusView( bool src )
    2. {
    3. if (src) {
    4. tabWidget->setCurrentIndex(1); /* QTextBrowser view + edit */
    5. } else {
    6. tabWidget->setCurrentIndex(0); /* QTextEdit source edit */
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT4 DomXPath / DomElementContainer find tag.

    Mmmm.... Write more clearly you should. Understand you I do not...

  7. #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: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by wysota View Post
    Mmmm.... Write more clearly you should. Understand you I do not...
    Why You say "QTextBrowser is read-only"!?

    setReadOnly(false); and the gui edit text ... table image like frontpage from MS$

    I am the first one that I write them within (QTextBrowser)?

    IMO: steep by steep i learn en_GB or US? after I find courage to write in the wiki without
    cin->getline(This article or section needs a rewrite!.)

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by patrik08 View Post
    Why You say "QTextBrowser is read-only"!?
    Because it is read only... That's why it's called a browser and not an editor. Quoting the docs:
    Quote Originally Posted by QTextBrowser reference
    This class extends QTextEdit (in read-only mode), adding some navigation functionality so that users can follow links in hypertext documents.
    I am the first one that I write them within (QTextBrowser)?
    Could be. Others have read the docs

    IMO: steep by steep i learn en_GB or US?
    Hmmm... What? Oh... you mean that step by step you learn to speak English? Maybe... I don't know. I think people (me too) are sometimes having trouble understanding what you say and according to me your main problem is that you don't use full sentences but instead you use arrows (->), dots (...), etc. This doesn't really help us (at least me) understand you. If you used full sentences, even ones containing mistakes, it would be easier to guess what you mean.

    after I find courage to write in the wiki without
    cin->getline(This article or section needs a rewrite!.)
    A suggestion for a rewrite may be caused not only by the language but also by the contents which may be unclear or seem irrelevant to the rest of the text.

  9. #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: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by wysota View Post
    Because it is read only... That's why it's called a browser and not an editor.
    Could be. Others have read the docs
    Me to and i found only one to display html page + link css image and open link on firefox .

    How you projekt a Wysiwyg xhtml editor without QTextBrowser ?
    To make a preview inside you need this QTextBrowser.
    QTextEdit dont dispay href link and open it. Boring event maybe? and make clickable.
    Otherwise you must open a new window to display and test links...

    Now i found a way to emulate XPath ....

    Now the problem is to contruct a new QDomNodeList and append note to return on public code...

    QDomNodeList not having append(node) !

    Qt Code:
    1. #include <iostream>
    2. #include <stdio.h>
    3. #include <unistd.h>
    4. #include <iostream>
    5. #include <QtCore>
    6. #include <QDomDocument>
    7.  
    8. class List_Tag
    9. {
    10. public:
    11. List_Tag( QDomDocument doc , const QString FindTagName , const QString AttributeName )
    12. {
    13. t = FindTagName;
    14. a = AttributeName;
    15.  
    16. std::cout << "Start Job search tag ->" << qPrintable(FindTagName) << std::endl;
    17. QDomNode n = doc.firstChild();
    18. if (n.hasChildNodes()) {
    19. Grep_Tag(n);
    20. }
    21. }
    22. protected:
    23. QString value;
    24. QString tagname;
    25. QDomNode node;
    26. private:
    27. void Grep_Tag( QDomNode n )
    28. {
    29. QDomNodeList list = n.childNodes();
    30. for (int i = 0; i < list.length(); ++i) {
    31. node = list.item(i);
    32. tagname = node.nodeName();
    33. std::cout << "Found tag loop->" << qPrintable(tagname) << std::endl;
    34. if (tagname == t && node.hasAttributes()) {
    35. value = node.toElement().attributeNode(a).value();
    36. if (!value.isEmpty()) {
    37. std::cout << "Result->" << qPrintable(tagname) << " attribute->" << qPrintable(value) << std::endl;
    38. }
    39. } else if (tagname == t && a.isEmpty()) {
    40. std::cout << "Result->" << qPrintable(tagname) << " and Empty attribute." << std::endl;
    41. }
    42. if (node.hasChildNodes()) {
    43. Grep_Tag(list.item(i));
    44. }
    45. }
    46. }
    47.  
    48. };
    49.  
    50. int main(int argc, char *argv[]) {
    51. QCoreApplication a( argc, argv );
    52.  
    53. const char *xml = "<test><tag>content 1</tag><tag>content 2</tag> "
    54. "<othertag>wrongcontent<p>text line <a href=\"/somelink\">link1</a></p></othertag>"
    55. "<tag>content 3 <div><p>text other <a href=\"/otherlink\">link2</a></p></div></tag></test>";
    56. bool ok = doc.setContent(QString(xml));
    57. if (ok) {
    58. List_Tag links(doc,"a","href");
    59. List_Tag paras(doc,"p","");
    60. }
    61. std::cout << "Main end..................." << std::endl;
    62. return a.exec();
    63. }
    64.  
    65. ////////#include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by patrik08 View Post
    Me to and i found only one to display html page + link css image and open link on firefox .
    Sorry, I don't understand what you mean.

    How you projekt a Wysiwyg xhtml editor without QTextBrowser ?
    To make a preview inside you need this QTextBrowser.
    QTextEdit dont dispay href link and open it. Boring event maybe? and make clickable.
    Otherwise you must open a new window to display and test links...
    I'd probably use QGraphicsView instead of QTextBrowser. If you want a wysiwyg editor, you have to be able to manipulate objects and QGraphicsView seems perfect for that.

    Now the problem is to contruct a new QDomNodeList and append note to return on public code...
    Your code is very cluttered with unnecessary debugging output. You should remove such lines before posting them here.

    From what I understand you wish to emulate "getElementsByName", right? Why not use QDomElement::elementsByTagName( const QString & tagname ) then?

  11. #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: QT4 DomXPath / DomElementContainer find tag.

    Quote Originally Posted by wysota View Post
    I'd probably use QGraphicsView instead of QTextBrowser. If you want a wysiwyg editor, you have to be able to manipulate objects and QGraphicsView seems perfect for that.
    Exact , fortunately you understand me.

    QGraphicsView , this is my weakness i not found enought sample or demo , wiki or so , to learn this.

    My target is to construct a editor like Scribus , only on xml way. At end by using relax NG its can write KDE docbook file or xml , and all xml semantic. Only swap the relax file, and other format can write.


    My actual XHTML editor to home page CMS is Bitflux editor ,
    http://cvsdemo.bitfluxeditor.org/exa...TML/index.html test it
    run only on Firefox and other Gecko Browser..
    The big advantage from this XML editor is:
    1 - http://en.wikipedia.org/wiki/RELAX_NG Relax NG ( http://www.w3.org/TR/xhtml2/xhtml20_relax.html )
    2 - I can set a 100% corporate identity from clients and the person editor can not mistake page why i set a schema to hadle this. If i say param is blue and red, only this color can write.
    3 - Write all xml format rss and more like apache fop pdf excel latex ( at end only xslt) http://bitfluxeditor.org/

    Example relax ng shema to xhtml:
    http://cvsdemo.bitfluxeditor.org/exa...ML/relaxng.xml

    Have you QGraphicsView sample or how much i must pay for that?
    I understand only draw on paintevent and pixmap.

Similar Threads

  1. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15

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
  •  
Qt is a trademark of The Qt Company.