Results 1 to 2 of 2

Thread: Getting All Text Between Tags in XML ?

  1. #1
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting All Text Between Tags in XML ?

    Lets say the xml file looks like:
    Qt Code:
    1. <article>
    2. <title>Help</title>
    3. <abstract>
    4. <p>First pgraph.</p>
    5. <p>Second pgraph</p>
    6. </abstract>
    7. </article>
    To copy to clipboard, switch view to plain text mode 
    and I want to extract everything (data as well as tags) between the abstract tags so I could put that in a string. The thing I extract would then be:

    Qt Code:
    1. <p>First pgraph.</p>
    2. <p>Second pgraph</p>
    To copy to clipboard, switch view to plain text mode 

    Anybody know how to do this?

  2. #2
    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: Getting All Text Between Tags in XML ?

    Quote Originally Posted by seanmu13 View Post
    Lets say the xml file looks like:
    [CODE]
    <article>
    <title>Help</title>
    <abstract>
    <p>First pgraph.</p>
    <p>Second pgraph</p>
    </abstract>
    </article>
    ow to do this?

    get the dom from abstract and create a new QDomDocument and catch as QString xml_xhtml = mdoc1.toString();

    this sample fill 6 qtextedit on a tab from a loop <page language="en"> on 6 language ....



    Qt Code:
    1. QDomElement xpage = root.firstChildElement("page");
    2. while (!xpage.isNull()) {
    3. QDomElement edomactual = xpage;
    4. QString hla = doc.GetAtt(xpage,"human"); /* humanlanguage string */
    5. QString xla = doc.GetAtt(xpage,"la"); /* iso browser language string 2 size */
    6. ///////////qDebug() << "### xmlloop " << xla;
    7. bodyxhtml = xpage.firstChildElement("body");
    8. htmldiv = bodyxhtml.firstChildElement("div");
    9. QDomDocument mdoc1;
    10. html = mdoc1.createElement("body");
    11. html.setAttribute ("BGCOLOR",BGCOLORPAGES);
    12. html.setAttribute ("style","la="+xla);
    13. html.appendChild( htmldiv );
    14. mdoc1.appendChild( html );
    15. QString xml_xhtml = mdoc1.toString();
    16. xml_xhtml = xml_xhtml.replace("<div class=\"qtpage\" xmlns=\"http://www.w3.org/1999/xhtml\" >","");
    17. xml_xhtml = xml_xhtml.replace("</div>","");
    18. xml_xhtml = xml_xhtml.replace(QString("src=\"./"),QString("src=\"%1").arg(Work_imcache),Qt::CaseInsensitive);
    19. xml_xhtml = xml_xhtml.replace(QString("src=\"/%1").arg(ServerPath),QString("src=\"%1").arg(Work_imcache),Qt::CaseInsensitive);
    20.  
    21. QString prehtml ="<html><head><meta name=\"qrichtext\" content=\"1\" />"
    22. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
    23. "<style type=\"text/css\">"
    24. "p, li { white-space: pre-wrap; } "
    25. "</style></head>";
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 8th June 2007 at 16:37.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  4. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

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.