Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt XmlStreamReader "Extra content at end of document." while meeting a startelement
Forum Updated to NodeBB v4.3 + New Features

Qt XmlStreamReader "Extra content at end of document." while meeting a startelement

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 431 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Puppy BearP Offline
    Puppy BearP Offline
    Puppy Bear
    wrote on last edited by Puppy Bear
    #1

    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 BearP 1 Reply Last reply
    0
    • Puppy BearP Puppy Bear

      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 BearP Offline
      Puppy BearP Offline
      Puppy Bear
      wrote on last edited by
      #2

      @Puppy-Bear AHA It seems that I've made a XML error copied by others,
      Try to add a root node would work!

      JonBJ 1 Reply Last reply
      0
      • Puppy BearP Puppy Bear

        @Puppy-Bear AHA It seems that I've made a XML error copied by others,
        Try to add a root node would work!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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....

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved