Ask Your Question

Valid XML should start with '<?xml ...?>' in function icvXMLParse

asked 2014-12-26 08:08:47 -0500

Fe++ gravatar image

updated 2014-12-26 09:23:17 -0500

berak gravatar image

I am reading the following yaml file, converted from the xml of pascal VOC 2007:

  filename: 000001.jpg
  folder: VOC2007
  - bndbox: {xmax: '195', xmin: '48', ymax: '371', ymin: '240'}
    difficult: '0'
    name: dog
    pose: Left
    truncated: '1'
  - bndbox: {xmax: '352', xmin: '8', ymax: '498', ymin: '12'}
    difficult: '0'
    name: person
    pose: Left
    truncated: '1'
  owner: {flickrid: Fried Camels, name: Jinky the Fruit Bat}
  segmented: '0'
  size: {depth: '3', height: '500', width: '353'}
  source: {annotation: PASCAL VOC2007, database: The VOC2007 Database, flickrid: '341012865',
    image: flickr}


FileStorage fs(fName, FileStorage::READ);

I get this error:

OpenCV Error: Parsing error (/opt/Datasets/VOCdevkit_test/VOC2007/Annotations/000001.yml(1): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /home/alessandro/OpenCV/opencv-2.4.10.x-prep/modules/core/src/persistence.cpp, line 2252 terminate called after throwing an instance of 'cv::Exception' what(): /home/alessandro/OpenCV/opencv-2.4.10.x-prep/modules/core/src/persistence.cpp:2252: error: (-212) /opt/Datasets/VOCdevkit_test/VOC2007/Annotations/000001.yml(1): Valid XML should start with '<?xml ...?>' in function icvXMLParse

Aborted (core dumped) It is from an existing open source code that has worked in others settings. Does anyone idea of the problem? Is something related with OpenCv version? I am using 2.4.10

edit retag flag offensive close merge delete


* how did you convert it from xml to yaml ? * can you try to insert a `%YAML:1.0` line at the top ?

berak gravatar imageberak ( 2014-12-26 10:29:52 -0500 )edit

I'm getting the same error. It works fine with an xml file, but in order to be consistent with the other part of our system, I needed to read in the data in yaml format. I do the same thing as you, and get the same error :-( It's trying to read it as an xml though it's supposed to know it's yaml from the extension!

mannyglover gravatar imagemannyglover ( 2017-01-17 15:20:16 -0500 )edit

Hmm somehow hes parsing the yaml file as xml - maybe you need to use a yaml parser instead of xml one.

Look at the error " icvXMLParse..." So look abit around the api to find the correct configuration. Esp look at the FileStorage class You can use an enum mode for the FileStorage Constructor telling the format. I think the rest you can do by yourself.

holger gravatar imageholger ( 2018-10-10 10:55:14 -0500 )edit

i guess, the op simply forgot to rename the files to .yml (cv::FileStorage is actually looking at the extension first)

berak gravatar imageberak ( 2018-10-10 10:58:19 -0500 )edit

Ahh - so you dont even have to configure explicitly. Thats convenient :-) Berak most likely gave the solution to the problem. Upvoted. If its working please close the thread as solved.

holger gravatar imageholger ( 2018-10-10 10:59:38 -0500 )edit

look at the date. q. from 2014

berak gravatar imageberak ( 2018-10-10 11:03:12 -0500 )edit

Oh man - thats the 2nd time it happens. That also explains opencv2.4.1... Sorry :-)

holger gravatar imageholger ( 2018-10-10 11:04:57 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-10-10 10:04:38 -0500

mfischer-gundlach gravatar image


your problem is most likely related to bom encoding. I am working on windows and can remove it via the power shell and there are solutions for each platform.

If you create the XML yourself, rather write the file without bom in first place.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-12-26 08:08:47 -0500

Seen: 5,143 times

Last updated: Oct 10 '18