Ask Your Question
1

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

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

stmo gravatar image

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

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

Thanks!

edit retag flag offensive close merge delete

Comments

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

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

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

<opencv_storage>

<Product>

<Code> 9HJC031024P1 </Code>

</Product>

</opencv_storage>

--This is what I've done:

FileStorage fs2;

fs2.open("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 -0600 )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 -0600 )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)...do you know another way to extract informations from a xml file using openCV?

stmo gravatar imagestmo ( 2014-02-07 07:14:00 -0600 )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 -0600 )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 -0600 )edit

yes. much easier then.

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

I will try in this way! Thanks again!

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

1 answer

Sort by ยป oldest newest most voted
0

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

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

Question Tools

Stats

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

Seen: 1,545 times

Last updated: Feb 07 '14