您好,问题是我正在使用QXmlStreamReader读取XML文件以读取我的日历的约会,但是当我从AppointmentSolo切换到AppointmentRepeat时,由于某种原因,atEnd()返回true。这是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" falsetrue "AppointmentRepeat" true3看来这是QXmlStreamReader :: NotWellFormedError由于读取的XML格式不正确,解析器在内部引发错误。但是,为什么我的XML格式不正确?编辑:似乎发生了错误(我添加了“ (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 XML只能有one root element,因此您的XML无效。 (adsbygoogle = window.adsbygoogle || []).push({});
08-27 02:28