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. XML Parser giving error if xml filename is only numbers.

XML Parser giving error if xml filename is only numbers.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.9k Views
  • 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.
  • K Offline
    K Offline
    kpkale
    wrote on last edited by
    #1

    I am using the following function for parsing an xml file.
    @QDomElement readallxml::parseXML(QString fileName)
    {
    QDomElement rootTag;
    QDomDocument docum;
    parseOK = false;
    QFile *file = new QFile(fileName);
    if(!(file->open(QIODevice::ReadOnly | QIODevice::Text)))
    return rootTag;
    QString errorStr;
    int errorLine;
    int errorColumn;
    if (!docum.setContent(file, false, &errorStr, &errorLine,
    &errorColumn)) {
    qDebug() << "Error: Parse error at line " << errorLine << ", "
    << "column " << errorColumn << ": "<< qPrintable(errorStr);
    file->close();
    return rootTag;
    }
    //Get the root element
    rootTag = docum.documentElement();
    file->close();
    parseOK=true;
    return rootTag;
    }@

    If the name of my xml file is say abc.xml then this routine works great. However, if my filename is 123.xml then setContent gives an error...Error: Parse error at line 1 , column 11 : letter is expected (as printed by qdebug)

    I tried to find out if there is any rule that xml filename should start with an alphabet, but could not locate any. If I change the filename and the corresponding document element names from 123.xml to a123.xml, then I have no error.
    Is there a better way to ensure that the numerical name file be parsed properly?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is no rule specified as file should start with 123.xml. Filename is coming from OperatingSystem. It is failing at setContent. It means that is parsing issue at the file. Can you paste the sample file which you are using ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kpkale
        wrote on last edited by
        #3

        Thanks Dheerendra for your reply.

        The xml file contents are as below. The name of this xml file is 520.xml
        @
        <!DOCTYPE 520>
        <520>
        <DesignName>a520</DesignName>
        <DotDistance>0.5000</DotDistance>
        <DotRepeat>1</DotRepeat>
        <FalseOrigin>0</FalseOrigin>
        <XOrigin>0.0000</XOrigin>
        <YOrigin>0.0000</YOrigin>
        <ZOrigin>0.0000</ZOrigin>
        <ROrigin>0.0000</ROrigin>
        <JobDiameter>30.0000</JobDiameter>
        <NameofMachine>BASIC_Marking_Machine.sem</NameofMachine>
        <CSVFile>NOFILE</CSVFile>
        <MarkRepeat>1</MarkRepeat>
        <MarkSpeed>80</MarkSpeed>
        <MoveSpeed>90</MoveSpeed>
        <ONDelay>6</ONDelay>
        <OFFDelay>6</OFFDelay>
        <StylusType>0</StylusType>
        <TotalMarkCount>0</TotalMarkCount>
        <CSVEnabled>0</CSVEnabled>
        <NoofGroupITems>0</NoofGroupITems>
        </520>
        @

        Now here, if I change manually from 520 to a520 this gets parsed without any problem. But the 520 does not get parsed.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Please look at the second rule. It is because of name starting with numbers.

          XML Naming Rules

          XML elements must follow these naming rules:

          Names can contain letters, numbers, and other characters
          Names cannot start with a number or punctuation character
          Names cannot start with the letters xml (or XML, or Xml, etc)
          Names cannot contain spaces
          

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kpkale
            wrote on last edited by
            #5

            OH. Thanks Dheerendra
            I was using the XML format to save my design files in the software. So in that case, I might have to switch over to some other format. Cannot lay rules to a user not to use numbers as the starting character for the design files.

            If you dont mind, any suggestions for any alternate format for saving files?

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              File name can be saved in number format. XML element name should not start with numbers. In your file you have 520 as XML tag. According to the rules tag name starting with number is not allowed. Hope it is clear.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kpkale
                wrote on last edited by
                #7

                OK I got it. Thanks Dheerendra.

                1 Reply Last reply
                0

                • Login

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