1

我在阅读以下 Xml 文件时遇到问题:

<ArrayOfScore xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Score><GameKey>201610629</GameKey><SeasonType>1</SeasonType><Season>2016</Season><Week>6</Week><Date>2016-10-13T20:25:00</Date><AwayTeam>DEN</AwayTeam><HomeTeam>SD</HomeTeam><AwayScore>13</AwayScore><HomeScore>21</HomeScore><Channel i:nil="true"/><PointSpread>3.0</PointSpread><OverUnder>44.5</OverUnder><Quarter>F</Quarter><TimeRemaining i:nil="true"/><Possession i:nil="true"/><Down i:nil="true"/><Distance i:nil="true"/><YardLine i:nil="true"/><YardLineTerritory i:nil="true"/><RedZone i:nil="true"/><AwayScoreQuarter1>0</AwayScoreQuarter1><AwayScoreQuarter2>3</AwayScoreQuarter2><AwayScoreQuarter3>0</AwayScoreQuarter3><AwayScoreQuarter4>10</AwayScoreQuarter4><AwayScoreOvertime>0</AwayScoreOvertime><HomeScoreQuarter1>7</HomeScoreQuarter1><HomeScoreQuarter2>3</HomeScoreQuarter2><HomeScoreQuarter3>9</HomeScoreQuarter3><HomeScoreQuarter4>2</HomeScoreQuarter4><HomeScoreOvertime>0</HomeScoreOvertime><HasStarted>true</HasStarted><IsInProgress>false</IsInProgress><IsOver>true</IsOver><Has1stQuarterStarted>true</Has1stQuarterStarted><Has2ndQuarterStarted>true</Has2ndQuarterStarted><Has3rdQuarterStarted>true</Has3rdQuarterStarted><Has4thQuarterStarted>true</Has4thQuarterStarted><IsOvertime>false</IsOvertime><DownAndDistance i:nil="true"/><QuarterDescription>Final</QuarterDescription><StadiumID>14</StadiumID><LastUpdated>2016-10-17T14:27:48</LastUpdated><GeoLat>32.783188</GeoLat><GeoLong>-117.119439</GeoLong><ForecastTempLow>58</ForecastTempLow><ForecastTempHigh>76</ForecastTempHigh><ForecastDescription>Sunny</ForecastDescription><ForecastWindChill>70</ForecastWindChill><ForecastWindSpeed>14</ForecastWindSpeed><AwayTeamMoneyLine>-160</AwayTeamMoneyLine><HomeTeamMoneyLine>140</HomeTeamMoneyLine><Canceled>false</Canceled><Closed>true</Closed><LastPlay i:nil="true"/><StadiumDetails><StadiumID>14</StadiumID><Name>Qualcomm Stadium</Name><City>San Diego</City><State>CA</State><Country>USA</Country><Capacity>70561</Capacity><PlayingSurface>Grass</PlayingSurface><GeoLat>32.783188</GeoLat><GeoLong>-117.119439</GeoLong></StadiumDetails></Score></ArrayOfScore>

我使用以下代码尝试读取元素:

QFile testxml("./test.xml");
if(testxml.open(QIODevice::ReadOnly)) {
    QXmlStreamReader XMLData(&testxml);
    while(!XMLData.atEnd() && !XMLData.hasError()) {
        XMLData.readNext();
        qDebug() << XMLData.readElementText();
        if(XMLData.isStartElement()) {
            qDebug() << XMLData.name();
            qDebug() << XMLData.readElementText();
        }
    }
}

但我只得到两个空字符串。

我尝试阅读另一个看起来非常相似的 XML 文件,它也是一行中的所有内容,我可以成功解析元素。有了这个文件,它就无法正常工作。

有谁知道我做错了什么?

4

0 回答 0