Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Parsing XML stop on Item inside Item



  • Hello,

    I'm trying to parse XML but in the line I need to read as text I have :

    //<HotLink targetrefid="../xml/37-00-00-001.xml" type="intraM" wp:type="container">Chapter 37-00-00, 001</HotLink>
    

    then the string stop before it.

    How can I have result like:

    Vacuum pressure for the pressure controller is controlled by the vacuum regulator that also regulates instrument vacuum. The regulator is located immediately forward of the forward pressure bulkhead. Refer to Chapter 37-00-00, 001 for further information on the vacuum regulator.

    here the XML interested line

    <Para NCW_TextAlign="Left" wp:type="para">
    Vacuum pressure for the pressure controller is controlled by the vacuum regulator that also regulates instrument vacuum. The regulator is located immediately forward of the forward pressure bulkhead. Refer to <HotLink targetrefid="../xml/37-00-00-001.xml" type="intraM" wp:type="container">Chapter 37-00-00, 001</HotLink> for further information on the vacuum regulator.
    </Para>
    

    here my part of code:

        QFile file("C:/XML/21-30-00-001.xml");
        if(!file.open(QFile::ReadOnly | QFile::Text)){
            qDebug() << "Cannot read file" << file.errorString();
            exit(0);
        }
        QXmlStreamReader xml(&file);
        QString Para;
        QString HotLink;
    
        while (!xml.atEnd())
        {xml.readNext();
    
            if (xml.isStartElement())
            {
                QString name = xml.name().toString();
                if (name == "Para")
                {
    
                    Para=xml.readElementText();
                }
    
                qDebug() << Para;
    
            }
    
        }
    

    and the string result on console:

    "\nVacuum pressure for the pressure controller is controlled by the vacuum regulator that also regulates instrument vacuum. The regulator is located immediately forward of the forward pressure bulkhead. Refer to "
    

    thank you very much for your help



  • Solved with

    Para=xml.readElementText(QXmlStreamReader::IncludeChildElements);
    

Log in to reply