c++ - QXmlStreamReader 说我在 XML 文件的末尾,而在它的中间

标签 c++ xml qt

你好,问题是我正在使用 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/

相关文章:

C++:在抛出 'std::bad_alloc' 实例后调用终止

xml - 在输出中的元素上显式显示默认命名空间

javascript - 有没有简单的方法来清除 SVG 元素的内容?

python - PyQt:removeChild/addChild QGroupBox

c++ - Q_DECLARE_METATYPE 期望 ctor、dtor 或之前的类型转换; token

qt - 在图形 View 中显示图 block map 和其他对象的最佳方式是什么?

c++ - 什么是 diff b/w Includes in VC++ Directories options 和 Additional include directories in C++ -> General in Visual Studio

c++ - 创建自定义运算符 c++

c++ - -mmacosx-version-min 影响位域的打包行为?

java - Android Studio - 权重总和