namespace Xilium.CefGlue
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Xilium.CefGlue.Interop;
///
/// Class that supports the reading of XML data via the libxml streaming API.
/// The methods of this class should only be called on the thread that creates
/// the object.
///
public sealed unsafe partial class CefXmlReader
{
///
/// Create a new CefXmlReader object. The returned object's methods can only
/// be called from the thread that created the object.
///
public static CefXmlReader Create(CefStreamReader stream, CefXmlEncoding encodingType, string uri)
{
if (stream == null) throw new ArgumentNullException("stream");
fixed (char* uri_str = uri)
{
var n_uri = new cef_string_t(uri_str, uri != null ? uri.Length : 0);
return CefXmlReader.FromNative(
cef_xml_reader_t.create(stream.ToNative(), encodingType, &n_uri)
);
}
}
///
/// Moves the cursor to the next node in the document. This method must be
/// called at least once to set the current cursor position. Returns true if
/// the cursor position was set successfully.
///
public bool MoveToNextNode()
{
return cef_xml_reader_t.move_to_next_node(_self) != 0;
}
///
/// Close the document. This should be called directly to ensure that cleanup
/// occurs on the correct thread.
///
public bool Close()
{
return cef_xml_reader_t.close(_self) != 0;
}
///
/// Returns true if an error has been reported by the XML parser.
///
public bool HasError
{
get { return cef_xml_reader_t.has_error(_self) != 0; }
}
///
/// Returns the error string.
///
public string Error
{
get
{
var n_result = cef_xml_reader_t.get_error(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// The below methods retrieve data for the node at the current cursor
/// position.
/// Returns the node type.
///
public CefXmlNodeType NodeType
{
get { return cef_xml_reader_t.get_type(_self); }
}
///
/// Returns the node depth. Depth starts at 0 for the root node.
///
public int Depth
{
get { return cef_xml_reader_t.get_depth(_self); }
}
///
/// Returns the local name. See
/// http://www.w3.org/TR/REC-xml-names/#NT-LocalPart for additional details.
///
public string LocalName
{
get
{
var n_result = cef_xml_reader_t.get_local_name(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns the namespace prefix. See http://www.w3.org/TR/REC-xml-names/ for
/// additional details.
///
public string Prefix
{
get
{
var n_result = cef_xml_reader_t.get_prefix(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns the qualified name, equal to (Prefix:)LocalName. See
/// http://www.w3.org/TR/REC-xml-names/#ns-qualnames for additional details.
///
public string QualifiedName
{
get
{
var n_result = cef_xml_reader_t.get_qualified_name(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns the URI defining the namespace associated with the node. See
/// http://www.w3.org/TR/REC-xml-names/ for additional details.
///
public string NamespaceUri
{
get
{
var n_result = cef_xml_reader_t.get_namespace_uri(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns the base URI of the node. See http://www.w3.org/TR/xmlbase/ for
/// additional details.
///
public string BaseUri
{
get
{
var n_result = cef_xml_reader_t.get_base_uri(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns the xml:lang scope within which the node resides. See
/// http://www.w3.org/TR/REC-xml/#sec-lang-tag for additional details.
///
public string XmlLang
{
get
{
var n_result = cef_xml_reader_t.get_xml_lang(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns true if the node represents an empty element. is considered
/// empty but is not.
///
public bool IsEmptyElement
{
get { return cef_xml_reader_t.is_empty_element(_self) != 0; }
}
///
/// Returns true if the node has a text value.
///
public bool HasValue
{
get { return cef_xml_reader_t.has_value(_self) != 0; }
}
///
/// Returns the text value.
///
public string Value
{
get
{
var n_result = cef_xml_reader_t.get_value(_self);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns true if the node has attributes.
///
public bool HasAttributes
{
get { return cef_xml_reader_t.has_attributes(_self) != 0; }
}
///
/// Returns the number of attributes.
///
public int AttributeCount
{
get { return (int)cef_xml_reader_t.get_attribute_count(_self); }
}
///
/// Returns the value of the attribute at the specified 0-based index.
///
public string GetAttribute(int index)
{
var n_result = cef_xml_reader_t.get_attribute_byindex(_self, index);
return cef_string_userfree.ToString(n_result);
}
///
/// Returns the value of the attribute with the specified qualified name.
///
public string GetAttribute(string qualifiedName)
{
fixed (char* qualifiedName_str = qualifiedName)
{
var n_qualifiedName = new cef_string_t(qualifiedName_str, qualifiedName != null ? qualifiedName.Length : 0);
var n_result = cef_xml_reader_t.get_attribute_byqname(_self, &n_qualifiedName);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns the value of the attribute with the specified local name and
/// namespace URI.
///
public string GetAttribute(string localName, string namespaceUri)
{
fixed (char* localName_str = localName)
fixed (char* namespaceUri_str = namespaceUri)
{
var n_localName = new cef_string_t(localName_str, localName != null ? localName.Length : 0);
var n_namespaceUri = new cef_string_t(namespaceUri_str, namespaceUri != null ? namespaceUri.Length : 0);
var n_result = cef_xml_reader_t.get_attribute_bylname(_self, &n_localName, &n_namespaceUri);
return cef_string_userfree.ToString(n_result);
}
}
///
/// Returns an XML representation of the current node's children.
///
public string GetInnerXml()
{
var n_result = cef_xml_reader_t.get_inner_xml(_self);
return cef_string_userfree.ToString(n_result);
}
///
/// Returns an XML representation of the current node including its children.
///
public string GetOuterXml()
{
var n_result = cef_xml_reader_t.get_outer_xml(_self);
return cef_string_userfree.ToString(n_result);
}
///
/// Returns the line number for the current node.
///
public int LineNumber
{
get { return cef_xml_reader_t.get_line_number(_self); }
}
///
/// Attribute nodes are not traversed by default. The below methods can be
/// used to move the cursor to an attribute node. MoveToCarryingElement() can
/// be called afterwards to return the cursor to the carrying element. The
/// depth of an attribute node will be 1 + the depth of the carrying element.
/// Moves the cursor to the attribute at the specified 0-based index. Returns
/// true if the cursor position was set successfully.
///
public bool MoveToAttribute(int index)
{
return cef_xml_reader_t.move_to_attribute_byindex(_self, index) != 0;
}
///
/// Moves the cursor to the attribute with the specified qualified name.
/// Returns true if the cursor position was set successfully.
///
public bool MoveToAttribute(string qualifiedName)
{
fixed (char* qualifiedName_str = qualifiedName)
{
var n_qualifiedName = new cef_string_t(qualifiedName_str, qualifiedName != null ? qualifiedName.Length : 0);
return cef_xml_reader_t.move_to_attribute_byqname(_self, &n_qualifiedName) != 0;
}
}
///
/// Moves the cursor to the attribute with the specified local name and
/// namespace URI. Returns true if the cursor position was set successfully.
///
public bool MoveToAttribute(string localName, string namespaceUri)
{
fixed (char* localName_str = localName)
fixed (char* namespaceUri_str = namespaceUri)
{
var n_localName = new cef_string_t(localName_str, localName != null ? localName.Length : 0);
var n_namespaceUri = new cef_string_t(namespaceUri_str, namespaceUri != null ? namespaceUri.Length : 0);
return cef_xml_reader_t.move_to_attribute_bylname(_self, &n_localName, &n_namespaceUri) != 0;
}
}
///
/// Moves the cursor to the first attribute in the current element. Returns
/// true if the cursor position was set successfully.
///
public bool MoveToFirstAttribute()
{
return cef_xml_reader_t.move_to_first_attribute(_self) != 0;
}
///
/// Moves the cursor to the next attribute in the current element. Returns
/// true if the cursor position was set successfully.
///
public bool MoveToNextAttribute()
{
return cef_xml_reader_t.move_to_next_attribute(_self) != 0;
}
///
/// Moves the cursor back to the carrying element. Returns true if the cursor
/// position was set successfully.
///
public bool MoveToCarryingElement()
{
return cef_xml_reader_t.move_to_carrying_element(_self) != 0;
}
}
}