I'm working on a C++ program and I need to read a piece of meta-data from a TIF file. The meta-data is a string that looks like the following:
<GDALMetadata>
<Item name="BANDWIDTH"></Item>
<Item name="CENTER_FILTER_WAVELENGTH"></Item>
<Item name="DATA_SET_ID">&quot;LRO-L-LOLA-4-GDR-V1.0&quot;</Item>
<Item name="FILTER_NAME"></Item>
<Item name="INSTRUMENT_ID">&quot;LOLA&quot;</Item>
<Item name="INSTRUMENT_NAME">&quot;LUNAR ORBITER LASER ALTIMETER&quot;</Item>
<Item name="MISSION_NAME"></Item>
<Item name="NOTE"></Item>
<Item name="PRODUCER_INSTITUTION_NAME">&quot;GODDARD SPACE FLIGHT CENTER&quot;</Item>
<Item name="PRODUCT_CREATION_TIME">2017-09-15</Item>
<Item name="START_TIME">2009-07-13T17:33:17</Item>
<Item name="STOP_TIME">2016-11-29T05:48:19</Item>
<Item name="OFFSET" sample="0" role="offset">1737400</Item>
<Item name="SCALE" sample="0" role="scale">0.5</Item>
</GDALMetadata>
I need to extract the scale
value (which in this case is 0.5). My first attempt was to use regex as follows:
float scale = 1;
std::regex rgx("*<Item name=\"SCALE\"*>(.*?)</Item>*");
std::smatch match;
if (std::regex_search(metadata.begin(), metadata.end(), match, rgx)) {
scale = static_cast<float>(std::atof(match.str().c_str()));
};
This did not work, and I'm unsure why. I'm very inexperienced with regex.
Obviously this looks like HTML but as I only need this one specific field I was thinking it should be simpler to simply try to extract that directly.