Ask Your Question

Read a code (numbers and letters) from a xml file - c++

asked 2014-02-07 04:23:55 -0500

stmo gravatar image

updated 2014-02-07 04:34:32 -0500

berak gravatar image

Hi! I have to read a code (numbers and letters) from a xml file. 9HJC031024P1 How can I do it with FileStorage class?? I can't use a String type because show me this error: there should be space between literals in icvXMLParseValue...


edit retag flag offensive close merge delete


maybe you need to show the relevant portion of the xml ?

berak gravatar imageberak ( 2014-02-07 04:35:22 -0500 )edit

<?xml version="1.0" encoding="UTF-8"?>



<Code> 9HJC031024P1 </Code>



--This is what I've done:

FileStorage fs2;"my_file.xml", FileStorage::READ);

FileNode Product = Device["Product"];

--Now I've to read the code and put it in a variable, but which type?

stmo gravatar imagestmo ( 2014-02-07 06:01:59 -0500 )edit

did you write that xml using the filestorage ? that code might need some adaption, i.e. "" around the string. also, if you'd want more than one in there, you#d need unique 'keys' , too ( "Product" is not unique. )

are there more product/code tags ?

berak gravatar imageberak ( 2014-02-07 06:41:45 -0500 )edit

Thanks berak! with "" around the string this problem is solved. Yes, I'm reading just now the documentation about keys because I will need more than one product tag. In origin this xml was not created using FileStorage, I've adapted it (not very well indeed) you know another way to extract informations from a xml file using openCV?

stmo gravatar imagestmo ( 2014-02-07 07:14:00 -0500 )edit

oh, if there's more Product tags, it won't work. FileStorage is basically a key-value store, it needs unique keys, and you haven't got those.

honestly i'd stop here, and look for alternatives. can't you throw it at some office prog, and export it as a simple csv/text file ?

save your time, don't try to bend it.

oh, btw: FileNode Code = fs["Product"]["Code"];

berak gravatar imageberak ( 2014-02-07 07:20:06 -0500 )edit

I understand...and from a csv file could I read and put in variables the informations I need? if I have more products and more codes too?

stmo gravatar imagestmo ( 2014-02-07 07:51:39 -0500 )edit

yes. much easier then.

berak gravatar imageberak ( 2014-02-07 07:58:20 -0500 )edit

I will try in this way! Thanks again!

stmo gravatar imagestmo ( 2014-02-07 08:02:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-03 01:03:30 -0500

Sakthi gravatar image

Please try with " " for string - type like below "9HJC031024P1"

?xml version="1.0" encoding="UTF-8"?> <opencv_storage> <product> "9HJC031024P1" </product> </opencv_storage>

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-02-07 04:23:55 -0500

Seen: 979 times

Last updated: Feb 07 '14