Read a code (numbers and letters) from a xml file - c++
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!
maybe you need to show the relevant portion of the xml ?
<?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?
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 ?
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?
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"];
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?
yes. much easier then.
I will try in this way! Thanks again!