1 //===-- XML.h ---------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_XML_h_
11 #define liblldb_XML_h_
15 #if defined( LIBXML2_DEFINED )
16 #include <libxml/xmlreader.h>
25 // Other libraries and framework includes
27 #include "lldb/lldb-private.h"
28 #include "llvm/ADT/StringRef.h"
29 #include "lldb/Core/StreamString.h"
30 #include "lldb/Core/StructuredData.h"
33 namespace lldb_private {
35 #if defined( LIBXML2_DEFINED )
36 typedef xmlNodePtr XMLNodeImpl;
37 typedef xmlDocPtr XMLDocumentImpl;
39 typedef void * XMLNodeImpl;
40 typedef void * XMLDocumentImpl;
45 typedef std::vector<std::string> NamePath;
46 typedef std::function <bool(const XMLNode &node)> NodeCallback;
47 typedef std::function <bool(const llvm::StringRef &name, const llvm::StringRef &value)> AttributeCallback;
54 XMLNode(XMLNodeImpl node);
58 explicit operator bool() const
76 GetElementText (std::string &text) const;
79 GetElementTextAsUnsigned (uint64_t &value, uint64_t fail_value = 0, int base = 0) const;
82 GetElementTextAsFloat (double &value, double fail_value = 0.0) const;
85 NameIs (const char *name) const;
97 GetAttributeValue(const char *name, const char *fail_value = NULL) const;
100 FindFirstChildElementWithName (const char *name) const;
103 GetElementForPath (const NamePath &path);
105 //----------------------------------------------------------------------
106 // Iterate through all sibling nodes of any type
107 //----------------------------------------------------------------------
109 ForEachSiblingNode (NodeCallback const &callback) const;
111 //----------------------------------------------------------------------
112 // Iterate through only the sibling nodes that are elements
113 //----------------------------------------------------------------------
115 ForEachSiblingElement (NodeCallback const &callback) const;
117 //----------------------------------------------------------------------
118 // Iterate through only the sibling nodes that are elements and whose
119 // name matches \a name.
120 //----------------------------------------------------------------------
122 ForEachSiblingElementWithName (const char *name, NodeCallback const &callback) const;
125 ForEachChildNode (NodeCallback const &callback) const;
128 ForEachChildElement (NodeCallback const &callback) const;
131 ForEachChildElementWithName (const char *name, NodeCallback const &callback) const;
134 ForEachAttribute (AttributeCallback const &callback) const;
148 explicit operator bool() const
160 ParseFile (const char *path);
163 ParseMemory (const char *xml, size_t xml_length, const char *url = "untitled.xml");
165 //----------------------------------------------------------------------
166 // If \a name is NULL, just get the root element node, else only return
167 // a value XMLNode if the name of the root element matches \a name.
168 //----------------------------------------------------------------------
170 GetRootElement(const char *required_name = nullptr);
176 ErrorCallback (void *ctx, const char *format, ...);
182 XMLDocumentImpl m_document;
183 StreamString m_errors;
186 class ApplePropertyList
191 ApplePropertyList(const char *path);
193 ~ApplePropertyList();
196 ParseFile (const char *path);
201 explicit operator bool() const
210 GetValueNode (const char *key) const;
213 GetValueAsString (const char *key, std::string &value) const;
215 StructuredData::ObjectSP
220 // Using a node returned from GetValueNode() extract its value as a
221 // string (if possible). Array and dictionary nodes will return false
222 // as they have no string value. Boolean nodes will return true and
223 // \a value will be "true" or "false" as the string value comes from
224 // the element name itself. All other nodes will return the text
225 // content of the XMLNode.
227 ExtractStringFromValueNode (const XMLNode &node, std::string &value);
229 XMLDocument m_xml_doc;
232 } // namespace lldb_private
234 #endif // liblldb_XML_h_