1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the name Chromium Embedded 14 // Framework nor the names of its contributors may be used to endorse 15 // or promote products derived from this software without specific prior 16 // written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // 30 // --------------------------------------------------------------------------- 31 // 32 // The contents of this file must follow a specific format in order to 33 // support the CEF translator tool. See the translator.README.txt file in the 34 // tools directory for more information. 35 // 36 37 #ifndef CEF_INCLUDE_CEF_XML_READER_H_ 38 #define CEF_INCLUDE_CEF_XML_READER_H_ 39 #pragma once 40 41 #include "include/cef_base.h" 42 #include "include/cef_stream.h" 43 44 /// 45 // Class that supports the reading of XML data via the libxml streaming API. 46 // The methods of this class should only be called on the thread that creates 47 // the object. 48 /// 49 /*--cef(source=library)--*/ 50 class CefXmlReader : public virtual CefBaseRefCounted { 51 public: 52 typedef cef_xml_encoding_type_t EncodingType; 53 typedef cef_xml_node_type_t NodeType; 54 55 /// 56 // Create a new CefXmlReader object. The returned object's methods can only 57 // be called from the thread that created the object. 58 /// 59 /*--cef()--*/ 60 static CefRefPtr<CefXmlReader> Create(CefRefPtr<CefStreamReader> stream, 61 EncodingType encodingType, 62 const CefString& URI); 63 64 /// 65 // Moves the cursor to the next node in the document. This method must be 66 // called at least once to set the current cursor position. Returns true if 67 // the cursor position was set successfully. 68 /// 69 /*--cef()--*/ 70 virtual bool MoveToNextNode() = 0; 71 72 /// 73 // Close the document. This should be called directly to ensure that cleanup 74 // occurs on the correct thread. 75 /// 76 /*--cef()--*/ 77 virtual bool Close() = 0; 78 79 /// 80 // Returns true if an error has been reported by the XML parser. 81 /// 82 /*--cef()--*/ 83 virtual bool HasError() = 0; 84 85 /// 86 // Returns the error string. 87 /// 88 /*--cef()--*/ 89 virtual CefString GetError() = 0; 90 91 // The below methods retrieve data for the node at the current cursor 92 // position. 93 94 /// 95 // Returns the node type. 96 /// 97 /*--cef(default_retval=XML_NODE_UNSUPPORTED)--*/ 98 virtual NodeType GetType() = 0; 99 100 /// 101 // Returns the node depth. Depth starts at 0 for the root node. 102 /// 103 /*--cef()--*/ 104 virtual int GetDepth() = 0; 105 106 /// 107 // Returns the local name. See 108 // http://www.w3.org/TR/REC-xml-names/#NT-LocalPart for additional details. 109 /// 110 /*--cef()--*/ 111 virtual CefString GetLocalName() = 0; 112 113 /// 114 // Returns the namespace prefix. See http://www.w3.org/TR/REC-xml-names/ for 115 // additional details. 116 /// 117 /*--cef()--*/ 118 virtual CefString GetPrefix() = 0; 119 120 /// 121 // Returns the qualified name, equal to (Prefix:)LocalName. See 122 // http://www.w3.org/TR/REC-xml-names/#ns-qualnames for additional details. 123 /// 124 /*--cef()--*/ 125 virtual CefString GetQualifiedName() = 0; 126 127 /// 128 // Returns the URI defining the namespace associated with the node. See 129 // http://www.w3.org/TR/REC-xml-names/ for additional details. 130 /// 131 /*--cef()--*/ 132 virtual CefString GetNamespaceURI() = 0; 133 134 /// 135 // Returns the base URI of the node. See http://www.w3.org/TR/xmlbase/ for 136 // additional details. 137 /// 138 /*--cef()--*/ 139 virtual CefString GetBaseURI() = 0; 140 141 /// 142 // Returns the xml:lang scope within which the node resides. See 143 // http://www.w3.org/TR/REC-xml/#sec-lang-tag for additional details. 144 /// 145 /*--cef()--*/ 146 virtual CefString GetXmlLang() = 0; 147 148 /// 149 // Returns true if the node represents an empty element. <a/> is considered 150 // empty but <a></a> is not. 151 /// 152 /*--cef()--*/ 153 virtual bool IsEmptyElement() = 0; 154 155 /// 156 // Returns true if the node has a text value. 157 /// 158 /*--cef()--*/ 159 virtual bool HasValue() = 0; 160 161 /// 162 // Returns the text value. 163 /// 164 /*--cef()--*/ 165 virtual CefString GetValue() = 0; 166 167 /// 168 // Returns true if the node has attributes. 169 /// 170 /*--cef()--*/ 171 virtual bool HasAttributes() = 0; 172 173 /// 174 // Returns the number of attributes. 175 /// 176 /*--cef()--*/ 177 virtual size_t GetAttributeCount() = 0; 178 179 /// 180 // Returns the value of the attribute at the specified 0-based index. 181 /// 182 /*--cef(capi_name=get_attribute_byindex,index_param=index)--*/ 183 virtual CefString GetAttribute(int index) = 0; 184 185 /// 186 // Returns the value of the attribute with the specified qualified name. 187 /// 188 /*--cef(capi_name=get_attribute_byqname)--*/ 189 virtual CefString GetAttribute(const CefString& qualifiedName) = 0; 190 191 /// 192 // Returns the value of the attribute with the specified local name and 193 // namespace URI. 194 /// 195 /*--cef(capi_name=get_attribute_bylname)--*/ 196 virtual CefString GetAttribute(const CefString& localName, 197 const CefString& namespaceURI) = 0; 198 199 /// 200 // Returns an XML representation of the current node's children. 201 /// 202 /*--cef()--*/ 203 virtual CefString GetInnerXml() = 0; 204 205 /// 206 // Returns an XML representation of the current node including its children. 207 /// 208 /*--cef()--*/ 209 virtual CefString GetOuterXml() = 0; 210 211 /// 212 // Returns the line number for the current node. 213 /// 214 /*--cef()--*/ 215 virtual int GetLineNumber() = 0; 216 217 // Attribute nodes are not traversed by default. The below methods can be 218 // used to move the cursor to an attribute node. MoveToCarryingElement() can 219 // be called afterwards to return the cursor to the carrying element. The 220 // depth of an attribute node will be 1 + the depth of the carrying element. 221 222 /// 223 // Moves the cursor to the attribute at the specified 0-based index. Returns 224 // true if the cursor position was set successfully. 225 /// 226 /*--cef(capi_name=move_to_attribute_byindex,index_param=index)--*/ 227 virtual bool MoveToAttribute(int index) = 0; 228 229 /// 230 // Moves the cursor to the attribute with the specified qualified name. 231 // Returns true if the cursor position was set successfully. 232 /// 233 /*--cef(capi_name=move_to_attribute_byqname)--*/ 234 virtual bool MoveToAttribute(const CefString& qualifiedName) = 0; 235 236 /// 237 // Moves the cursor to the attribute with the specified local name and 238 // namespace URI. Returns true if the cursor position was set successfully. 239 /// 240 /*--cef(capi_name=move_to_attribute_bylname)--*/ 241 virtual bool MoveToAttribute(const CefString& localName, 242 const CefString& namespaceURI) = 0; 243 244 /// 245 // Moves the cursor to the first attribute in the current element. Returns 246 // true if the cursor position was set successfully. 247 /// 248 /*--cef()--*/ 249 virtual bool MoveToFirstAttribute() = 0; 250 251 /// 252 // Moves the cursor to the next attribute in the current element. Returns 253 // true if the cursor position was set successfully. 254 /// 255 /*--cef()--*/ 256 virtual bool MoveToNextAttribute() = 0; 257 258 /// 259 // Moves the cursor back to the carrying element. Returns true if the cursor 260 // position was set successfully. 261 /// 262 /*--cef()--*/ 263 virtual bool MoveToCarryingElement() = 0; 264 }; 265 266 #endif // CEF_INCLUDE_CEF_XML_READER_H_ 267