bool decode_xmp (const std::string &xml, ImageSpec &spec) { #if DEBUG_XMP_READ std::cerr << "XMP dump:\n---\n" << xml << "\n---\n"; #endif if (! xml.length()) return true; for (size_t startpos = 0, endpos = 0; extract_middle (xml, endpos, "<rdf:Description", "</rdf:Description>", startpos, endpos); ) { // Turn that middle section into an XML document std::string rdf (xml, startpos, endpos-startpos); // scooch in #if DEBUG_XMP_READ std::cerr << "RDF is:\n---\n" << rdf << "\n---\n"; #endif pugi::xml_document doc; pugi::xml_parse_result parse_result = doc.load_buffer (&rdf[0], rdf.size()); if (! parse_result) { #if DEBUG_XMP_READ std::cerr << "Error parsing XML\n"; #endif return true; } // Decode the contents of the XML document (it will recurse) decode_xmp_node (doc.first_child(), spec); } return true; }
bool decode_xmp(const std::string& xml, ImageSpec& spec) { #if DEBUG_XMP_READ std::cerr << "XMP dump:\n---\n" << xml << "\n---\n"; #endif if (!xml.length()) return true; for (size_t startpos = 0, endpos = 0; extract_middle(xml, endpos, "<rdf:Description", "</rdf:Description>", startpos, endpos);) { // Turn that middle section into an XML document std::string rdf(xml, startpos, endpos - startpos); // scooch in #if DEBUG_XMP_READ std::cerr << "RDF is:\n---\n" << rdf << "\n---\n"; #endif pugi::xml_document doc; pugi::xml_parse_result parse_result = doc.load_buffer(&rdf[0], rdf.size(), pugi::parse_default | pugi::parse_fragment); if (!parse_result) { #if DEBUG_XMP_READ std::cerr << "Error parsing XML @" << parse_result.offset << ": " << parse_result.description() << "\n"; #endif // Instead of returning early here if there were errors parsing // the XML -- I have noticed that very minor XML malformations // are common in XMP found in files -- hope for the best and // go ahead and assume that maybe it managed to put something // useful in the resulting document. #if 0 return true; #endif } // Decode the contents of the XML document (it will recurse) decode_xmp_node(doc.first_child(), spec); } return true; }