Results 1 to 4 of 4

Thread: Mysterious QXMLStreamReader parsing behavior

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mysterious QXMLStreamReader parsing behavior

    Thanks for your help.

    I'll try to understand the example code with WhiteSpace and NewLine in mind.

  2. #2
    Join Date
    Apr 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mysterious QXMLStreamReader parsing behavior

    Hi,
    How about this xml document. Do you have any idea how to parse it using QXml StreamReader or QDomDocument??

    <p>
    There are two types of hydraulic tools for the connecting rod shank screws, see
    <ref xml:link="simple" inline="true" behavior="external" content-role="fig" href="fig-400731-low">Fig 07-20</ref>
    . The screws and nuts in the tool of
    <hp0>new design</hp0>
    (introduced in year 2001) should be replaced before reaching
    <hp0>1000</hp0>
    loading cycles, i.e raising the pressure to nominal value 1000 times).
    </p>

    Any help please. I have to read all of them.
    I am using things like this:
    QString content=reader.readElementText(QXmlStreamReader::I ncludeChildElements);
    it will include everything inside <p> tag including those ref hp0. Then, I will go back to the beginning of <p> tag and readNext() to read the attribute and value <ref> and <hp0> tag.

    while(!reader.isEndElement()||reader.name()!="p"){
    if(reader.isStartElement()){
    if(reader.name()=="ref"){
    QString displaytext=reader.readElementText();
    QXmlStreamAttributes attrs = reader.attributes();
    QString role=attrs.value("content-role").toString();
    QString href=attrs.value("href").toString();
    QString link="<a href=\""+role+";"+href+"\">["+displaytext+"]</a>";
    value.replace(displaytext,link);
    }else if(reader.name()=="hp0"){
    QString bold=reader.readElementText();
    int bindex=value.indexOf(bold);
    if(bindex!=-1&&value.indexOf("<b>"+bold+"</b>")==-1){
    value.replace(bindex,bold.length(),"<b>"+bold+"</b>");
    }
    }else{
    qDebug()<<"error. Undefined tag name inside <p>";
    qDebug()<<reader.name();
    }
    }
    reader.readNext();
    }

    HOWEVER, my big and funny problem is that with QXmlStreamReader we dont have the option to roll back to previous start tag. In this case when I use
    QString content=reader.readElementText(QXmlStreamReader::I ncludeChildElements);
    the current cursor is at the end of tab </p> and I can not roll back to the beginning of <p> tag to read <fig> and <hp0> tag
    Any help please.

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.