XmlNode - Hierarchical representation of XML
|
|
class XmlNode
This class represent the whole XML document as recursive hierarchic structure - each XmlNode can contain any number of child XmlNodes. XmlNode is mutable and U++ provides function to parse XML and store it to XmlNode and also to take XmlNode and create corresponding XML document.
XmlNode is moveable type with pick and optional deep copy transfer semantics
static const XmlNode& Void()
Returns a constant reference to XmlNode representing "nothing". This reference is used as return value in cases where there are missing requested elements.
bool IsVoid() const
Returns true if XmlNode is Void.
int GetType() const
Returns the type of node. Possible types are: XML_PI, XML_DECL, XML_COMMENT, XML_DOC, XML_TEXT, XML_TAG.
String GetText() const
String GetTag() const
Returns the text associated with node. If the node is XML_TAG, the text is tag-id. If the node is XML_TEXT, the text is ... the text. In other cases, like XML_PI, the text is the copy of element content.
bool IsTag() const
Returns true if node is XML_TAG.
bool IsTag(const char *tag) const
Returns true if node is XML_TAG and is equal to tag.
bool IsText() const
Returns true if node is
void Clear()
Clears all content.
void CreateTag(const char *tag)
Sets this XmlNode to represent XML tag with id tag.
void CreateText(const String& txt)
Sets this XmlNode to represent text with content txt.
void CreatePI(const String& pi)
Sets this XmlNode to represent processing info pi.
void CreateDecl(const String& decl)
Sets this XmlNode to represent XML declaration decl.
Sets this XmlNode to represent XML comment.
void CreateDocument()
Set this XmlNode to be the top-level document node.
bool IsEmpty() const
Returns true if this XmlNode represents XML_DOC and contains no content.
operator bool() const
Same as !IsEmpty().
int GetCount() const
Returns a number of contained XmlNode sub-nodes.
XmlNode& At(int i)
Returns sub-node at index i. If there is no such node (number of sub-nodes is less than i + 1), number of nodes is extended to i + 1 with empty nodes.
const XmlNode& Node(int i) const
Returns node at index i. If there is none, behavior is undefined. This function is possibly slightly faster than either At or operator[].
const XmlNode& operator[](int i) const
Returns i.
const XmlNode& operator[](const char *tag) const
Finds a XML_TAG sub-node with id tag and returns it. If no such node is found, returns Void().
XmlNode& Add()
Adds a new sub-node.
void Remove(int i)
Removes subnode at i.
void AddText(const String& txt)
Adds a new text sub-node (XML_TEXT) and assigns it a text txt.
int FindTag(const char *tag) const
Finds a XML_TAG sub-node with id tag and returns its index. If no such sub-node exists, returns negative number.
XmlNode& Add(const char *tag)
Adds a new XML_TAG node with id tag and returns a reference to it.
XmlNode& GetAdd(const char *tag)
XmlNode& operator()(const char *tag)
Returns a reference to XML_TAG subnode with id tag. If no such node exists, adds it.
void Remove(const char *tag)
Removes XML_TAG sub-node with tag id. If there is no such sub-node, nothing happens.
String GatherText() const
String operator~() const
Concatenates all XML_TEXT sub-nodes in order of increasing indicies.
bool HasTags() const
Returns true if the node has subtags.
int GetAttrCount() const
Returns the number of attributes of current node (it has to be XML_TAG to have any attributes - nonzero returned).
String AttrId(int i) const
Returns id of attribute i.
String Attr(int i) const
Returns the value of attribute i.
String Attr(const char *id) const
Returns the value of attribute id. If no such attribute exists, returns empty String.
XmlNode& SetAttr(const char *id, const String& val)
Sets the attribute id to have value val. Attribute does not have exist yet.
int AttrInt(const char *id, int def = Null) const
Returns the value of attribute id converted to integer. If no such attribute exists, returns def.
XmlNode& SetAttr(const char *id, int val)
Sets the attribute id to have integer value val.
void SetAttrs(VectorMap<String, String>&& a)
Replaces all attributes with picked a.
void SetAttrsPick(pick_ VectorMap<String, String>& a)
Replaces all attributes to a using pick operation (a is destroyed in operation).
void Shrink()
Attempts to minimize memory footprint.
bool IsPicked() const
Returns true if picked
XmlNode()
Construct an empty XmlNode.
XmlNode(const XmlNode& n, int)
Deep copy constructor.
XmlNode - parse and output functions
|
|
XmlNode ParseXML(XmlParser& p, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXML(const char *s, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXML(XmlParser& p, ParseXmlFilter& filter, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXML(const char *s, ParseXmlFilter& filter, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXML(Stream& in, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXMLFile(const char *path, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXML(Stream& in, ParseXmlFilter& filter, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
XmlNode ParseXMLFile(const char *path, ParseXmlFilter& filter, dword style = XML_IGNORE_DECLS|XML_IGNORE_PIS|XML_IGNORE_COMMENTS)
Creates XmlNode parsing XML document supplied either as XmlParser, string, input stream or file path. style can be a combination of
|
XML_IGNORE_DECLS
|
Declaration elements are ignored.
|
XML_IGNORE_PIS
|
Processing info elements are ignored.
|
XML_IGNORE_COMMENTS
|
Comments are ignored.
|
|
Variants with filter allow to speficy a filter class to exclude some parts of XML, usually to preserve memory. Can throw XmlError.
void AsXML(Stream& out, const XmlNode& n, dword style = XML_HEADER|XML_DOCTYPE|XML_PRETTY)
String AsXML(const XmlNode& n, dword style = XML_HEADER|XML_DOCTYPE|XML_PRETTY)
bool AsXMLFile(const char *path, const XmlNode& n, dword style = XML_HEADER|XML_DOCTYPE|XML_PRETTY)
Creates a XML document from XmlNode n. style can be a combination of
|
XML_HEADER
|
Adds standard XML header at the beginning of the document.
|
XML_DOCTYPE
|
Adds DOCTYPE declaration at the beginning of the document with type taken as id of first XML_TAG sub-node (which represents the root element).
|
XML_PRETTY
|
XML document is formatted as multiline document with nice indentation. If not active, everything is in sigle line with no identantion.
|
|
Output is stored to Stream, returned as String or (with AsXMLFile) stored to file. AsXMLFile returns true if output file was successfully created.
|