你好,问题是我正在使用 QXmlStreamReader 读取 XML 文件以读取日历的约会,但是当我从 AppointmentSolo
切换到 AppointmentRepeat
atEnd( ) 由于某种原因返回真。
这是 XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<AppointmentSolo>
<Length>1</Length>
<AppointmentSolo0>
<Date>10 09 2011</Date>
<Begin>15:11</Begin>
<End>23:12</End>
<Title>Final test</Title>
<Description>Final countdown</Description>
<hasNotify>1</hasNotify>
<notify>17</notify>
</AppointmentSolo0>
</AppointmentSolo>
<AppointmentRepeat>
<Length>1</Length>
<AppointmentRepeat0>
<Date>08 01 2014</Date>
<Begin>20:08</Begin>
<End>23:09</End>
<Type>MONTHLY</Type>
<Exceptions>
<Length>1</Length>
<Exception0>08 09 2014</Exception0>
</Exceptions>
<Title>Repeat test</Title>
<Description>FooBar</Description>
<hasNotify>0</hasNotify>
<notify>0</notify>
</AppointmentRepeat0>
</AppointmentRepeat>
这是我的代码读取它的部分以及问题发生的地方。
if(Rxml.isEndElement() && Rxml.name() == "AppointmentSolo")
{
qDebug() << Rxml.atEnd() << Rxml.name() << Rxml.hasError();
Rxml.readNext();
qDebug() << Rxml.atEnd() << Rxml.name() << Rxml.hasError();
qDebug() << Rxml.error();
while(!Rxml.atEnd() && !Rxml.isStartElement())//om aan begin tag te zijn
{
Rxml.readNext();
qDebug() << Rxml.atEnd() << Rxml.name() << Rxml.hasError();
}
}
这是输出结果
false "AppointmentSolo" false
true "AppointmentRepeat" true
3
这似乎是一个 QXmlStreamReader::NotWellFormedError 由于读取的 XML 格式不正确,解析器在内部引发错误。 但为什么我的 XML 格式不正确?
编辑:似乎发生了错误(我添加了“<< Rxml.hasError()”)
最佳答案
XML 只能有 one root element ,因此您的 XML 无效。
关于c++ - QXmlStreamReader 说我在 XML 文件的末尾,而在它的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25228737/