Qt XmlStreamReader "Extra content at end of document." while meeting a startelement
Solved
General and Desktop
-
Greetings,
I'm trying to read a xml file below, using Qt's xml reader, and willing to read all elements and add them to other functions.<<?xml version="1.0" encoding="UTF-8"?> <CreateTables> <!--增加表 --> <Table> <TableName>Student1</TableName> <!--表的名字 --> <FieldList>Name|Age|Gender</FieldList> <!--字段名字 用|来分割 字段个数和字段类型数一定要一一对应--> <FieldTypeList>VARCHAR(32)|INT|VARCHAR(8)</FieldTypeList> <!--字段类型 用|来分割--> </Table> <Table> <TableName>Student2</TableName> <!--表的名字 --> <FieldList>Name|Age|Gender</FieldList> <!--字段名字 用|来分割--> <FieldTypeList>VARCHAR(32)|INT|VARCHAR(9)</FieldTypeList> <!--字段类型 用|来分割 字段个数和字段类型数一定要一一对应--> </Table> </CreateTables> <DropTables> <!--删除加表 --> <Table> <TableName>Student1</TableName> <!--表的名字 --> </Table> <Table> <TableName>Student2</TableName> <!--表的名字 --> </Table> </DropTables> <AddField> <!--增加字段 --> <Table> <TableName>Student1</TableName> <!--表的名字 --> <FieldList>Grade|Number</FieldList> <!--字段名字 用|来分割--> <FieldTypeList>VARCHAR(32)|INT</FieldTypeList> <!--字段类型 用|来分割--> </Table> <Table> <TableName>Student2</TableName> <!--表的名字 --> <FieldList>Grade|Number</FieldList> <!--字段名字 用|来分割--> <FieldTypeList>VARCHAR(32)|INT</FieldTypeList> <!--字段类型 用|来分割--> </Table> </AddField>
But however, my xmlreader.isStartelement() only returns true while reading 'CreateTables',
without regarding 'DropTables' as startelement(),
xmlreader.hasError() goes "Extra content at end of document."
while meeting the DropTables.my code is below. Could anyone show me the error please?
while (!xmlreader.atEnd() || !xmlreader.hasError()) { xmlreader.readNextStartElement(); nodename = xmlreader.name().toString(); //First node if (xmlreader.isStartElement()) qDebug() << "START ELEMENT " << nodename << "\n"; }
-
@Puppy-Bear AHA It seems that I've made a XML error copied by others,
Try to add a root node would work! -
@Puppy-Bear
That would help! As would not starting your document with an illegal<<?xml version="1.0" encoding="UTF-8"?>
per what you have pasted....