1 #ifndef DYNAMIC_DEPTH_INTERNAL_XMPMETA_XML_UTILS_H_ // NOLINT 2 #define DYNAMIC_DEPTH_INTERNAL_XMPMETA_XML_UTILS_H_ // NOLINT 3 4 #include <libxml/tree.h> 5 6 #include <string> 7 8 #include "base/port.h" 9 10 namespace dynamic_depth { 11 namespace xmpmeta { 12 namespace xml { 13 14 // Convenience function to convert an xmlChar* to a char* FromXmlChar(const xmlChar * in)15inline const char* FromXmlChar(const xmlChar* in) { 16 return reinterpret_cast<const char*>(in); 17 } 18 19 // Convenience function to convert a char* to an xmlChar*. ToXmlChar(const char * in)20inline const xmlChar* ToXmlChar(const char* in) { 21 return reinterpret_cast<const xmlChar*>(in); 22 } 23 24 // Returns the first rdf:Description node; null if not found. 25 xmlNodePtr GetFirstDescriptionElement(xmlDocPtr parent); 26 27 // Returns the first rdf:Seq element found in the XML document. 28 xmlNodePtr GetFirstSeqElement(xmlDocPtr parent); 29 30 // Returns the first rdf:Seq element found in the given node. 31 // Returns {@code parent} if that is itself an rdf:Seq node. 32 xmlNodePtr GetFirstSeqElement(xmlNodePtr parent); 33 34 // Returns the ith (zero-indexed) rdf:li node in the given rdf:Seq node. 35 // Returns null if either of {@code index} < 0, {@code node} is null, or is 36 // not an rdf:Seq node. 37 xmlNodePtr GetElementAt(xmlNodePtr node, int index); 38 39 // Returns the value in an rdf:li node. This is for a node whose value 40 // does not have a name, e.g. <rdf:li>value</rdf:li>. 41 // If the given rdf:li node has a nested node, it returns the string 42 // representation of the contents of those nodes, which replaces the XML 43 // tags with one whitespace character for each tag character. 44 // This is treated as undefined behavior; it is the caller's responsibility 45 // to remove any whitespace and newlines. 46 const string GetLiNodeContent(xmlNodePtr node); 47 48 // Returns the given XML doc serialized to a string. 49 // For debugging purposes. 50 const string XmlDocToString(const xmlDocPtr doc); 51 52 } // namespace xml 53 } // namespace xmpmeta 54 } // namespace dynamic_depth 55 56 #endif // DYNAMIC_DEPTH_INTERNAL_XMPMETA_XML_UTILS_H_ // NOLINT 57