1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // ---------------------------------------------------------------------------
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.
37 #ifndef CEF_INCLUDE_CEF_XML_READER_H_
38 #define CEF_INCLUDE_CEF_XML_READER_H_
41 #include "include/cef_base.h"
42 #include "include/cef_stream.h"
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
49 /*--cef(source=library)--*/
50 class CefXmlReader : public virtual CefBase {
52 typedef cef_xml_encoding_type_t EncodingType;
53 typedef cef_xml_node_type_t NodeType;
56 // Create a new CefXmlReader object. The returned object's methods can only
57 // be called from the thread that created the object.
60 static CefRefPtr<CefXmlReader> Create(CefRefPtr<CefStreamReader> stream,
61 EncodingType encodingType,
62 const CefString& URI);
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.
70 virtual bool MoveToNextNode() =0;
73 // Close the document. This should be called directly to ensure that cleanup
74 // occurs on the correct thread.
77 virtual bool Close() =0;
80 // Returns true if an error has been reported by the XML parser.
83 virtual bool HasError() =0;
86 // Returns the error string.
89 virtual CefString GetError() =0;
92 // The below methods retrieve data for the node at the current cursor
96 // Returns the node type.
98 /*--cef(default_retval=XML_NODE_UNSUPPORTED)--*/
99 virtual NodeType GetType() =0;
102 // Returns the node depth. Depth starts at 0 for the root node.
105 virtual int GetDepth() =0;
108 // Returns the local name. See
109 // http://www.w3.org/TR/REC-xml-names/#NT-LocalPart for additional details.
112 virtual CefString GetLocalName() =0;
115 // Returns the namespace prefix. See http://www.w3.org/TR/REC-xml-names/ for
116 // additional details.
119 virtual CefString GetPrefix() =0;
122 // Returns the qualified name, equal to (Prefix:)LocalName. See
123 // http://www.w3.org/TR/REC-xml-names/#ns-qualnames for additional details.
126 virtual CefString GetQualifiedName() =0;
129 // Returns the URI defining the namespace associated with the node. See
130 // http://www.w3.org/TR/REC-xml-names/ for additional details.
133 virtual CefString GetNamespaceURI() =0;
136 // Returns the base URI of the node. See http://www.w3.org/TR/xmlbase/ for
137 // additional details.
140 virtual CefString GetBaseURI() =0;
143 // Returns the xml:lang scope within which the node resides. See
144 // http://www.w3.org/TR/REC-xml/#sec-lang-tag for additional details.
147 virtual CefString GetXmlLang() =0;
150 // Returns true if the node represents an empty element. <a/> is considered
151 // empty but <a></a> is not.
154 virtual bool IsEmptyElement() =0;
157 // Returns true if the node has a text value.
160 virtual bool HasValue() =0;
163 // Returns the text value.
166 virtual CefString GetValue() =0;
169 // Returns true if the node has attributes.
172 virtual bool HasAttributes() =0;
175 // Returns the number of attributes.
178 virtual size_t GetAttributeCount() =0;
181 // Returns the value of the attribute at the specified 0-based index.
183 /*--cef(capi_name=get_attribute_byindex,index_param=index)--*/
184 virtual CefString GetAttribute(int index) =0;
187 // Returns the value of the attribute with the specified qualified name.
189 /*--cef(capi_name=get_attribute_byqname)--*/
190 virtual CefString GetAttribute(const CefString& qualifiedName) =0;
193 // Returns the value of the attribute with the specified local name and
196 /*--cef(capi_name=get_attribute_bylname)--*/
197 virtual CefString GetAttribute(const CefString& localName,
198 const CefString& namespaceURI) =0;
201 // Returns an XML representation of the current node's children.
204 virtual CefString GetInnerXml() =0;
207 // Returns an XML representation of the current node including its children.
210 virtual CefString GetOuterXml() =0;
213 // Returns the line number for the current node.
216 virtual int GetLineNumber() =0;
219 // Attribute nodes are not traversed by default. The below methods can be
220 // used to move the cursor to an attribute node. MoveToCarryingElement() can
221 // be called afterwards to return the cursor to the carrying element. The
222 // depth of an attribute node will be 1 + the depth of the carrying element.
225 // Moves the cursor to the attribute at the specified 0-based index. Returns
226 // true if the cursor position was set successfully.
228 /*--cef(capi_name=move_to_attribute_byindex,index_param=index)--*/
229 virtual bool MoveToAttribute(int index) =0;
232 // Moves the cursor to the attribute with the specified qualified name.
233 // Returns true if the cursor position was set successfully.
235 /*--cef(capi_name=move_to_attribute_byqname)--*/
236 virtual bool MoveToAttribute(const CefString& qualifiedName) =0;
239 // Moves the cursor to the attribute with the specified local name and
240 // namespace URI. Returns true if the cursor position was set successfully.
242 /*--cef(capi_name=move_to_attribute_bylname)--*/
243 virtual bool MoveToAttribute(const CefString& localName,
244 const CefString& namespaceURI) =0;
247 // Moves the cursor to the first attribute in the current element. Returns
248 // true if the cursor position was set successfully.
251 virtual bool MoveToFirstAttribute() =0;
254 // Moves the cursor to the next attribute in the current element. Returns
255 // true if the cursor position was set successfully.
258 virtual bool MoveToNextAttribute() =0;
261 // Moves the cursor back to the carrying element. Returns true if the cursor
262 // position was set successfully.
265 virtual bool MoveToCarryingElement() =0;
268 #endif // CEF_INCLUDE_CEF_XML_READER_H_