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