XMLElementEx Class
The XMLElementEx is used for parsing and storing XML elements. More...
Header: | #include <XMLElementEx> |
Inherits: | XMLPrimitive |
Inherited By: |
Public Functions
XMLElementEx(XMLType_e eType = e_XMLElement) | |
virtual | ~XMLElementEx() |
void | AddAttribute(XMLAttribute *pAttr) |
virtual XMLElementEx * | AddChild(const char *xml, unsigned int &nLineNumber, int level = 0) |
virtual XMLElementEx * | AddChild(const std::string &xml, unsigned int &linenumber, int level = 0) |
XMLAttribute * | FindAttribute(const char *pzName) |
XMLAttribute * | FindAttribute(const std::string &name) |
XMLAttribute * | GetAttribute() |
bool | GetAttribute(const std::string &attrName, std::string &attrValue) |
XMLString | GetAttributeValue(const char *pzName) |
std::string | GetAttributeValue(const std::string &name) |
XMLElementEx * | GetChild(const char *pzName = NULL) const |
XMLElementEx * | GetChild(const std::string &name) const |
virtual bool | GetChildElement(const std::string &name, XMLElementEx *&pReturnChild) |
XMLElementEx * | GetNext(const char *pzName = NULL) const |
XMLElementEx * | GetPrevious(const char *pzName = NULL) const |
std::string | GetStrValue() const |
const XMLString & | GetValue() const |
bool | HasAttribute(const std::string &attrName) |
bool | HasChildElement(const std::string &name) |
void | RemoveChild(const std::string &elementName, const std::string &name) |
void | SetAttribute(XMLAttribute *pAtt) |
void | SetAttributeValue(const char *attributeName, const char *attributeValue) |
void | SetAttributeValue(const std::string &attributeName, const std::string &attributeValue) |
void | SetStrValue(const std::string &value) |
void | SetValue(XMLString newValue) |
Reimplemented Public Functions
virtual bool | Dump(FILE *pFile) |
virtual char * | Dump(char *pzBuffer) |
virtual void | Dump(XMLBuffer &strBuffer) |
virtual unsigned int | GetWriteBufferSize() |
virtual void | Merge(XMLPrimitive *pOther) |
virtual const char * | Parse(const char *pStart, unsigned int &nLineNumber) |
- 37 public functions inherited from XMLPrimitive
Additional Inherited Members
- 1 static public member inherited from XMLPrimitive
Detailed Description
The XMLElementEx is used for parsing and storing XML elements.
Functions can be called to parse an xml element, set and retrieve name and value, set, get, find attributes and to generate XML.
Element example
<Value Attribute="Value" SomeValue="2">1</Value>
From the above, 'Value' is the element Name. It can be retrieved by the GetName() function. '1' is the element value. It can be retrieved by the GetValue() function. Attributes can be retrieved using FindAttribute(attributeName); or GetAttributeValue(attributeName)
Example code, reading element example above:
XMLElementEx* pEx = parser.FindFirstElement("Value"); if(pEx!=nullptr && pEx->GetAttributeValue("Attribute")=="Value" && pEx->GetAttributeValue("SomeValue")=="2") assert(pEx->GetValue()==1);
Member Function Documentation
XMLElementEx::XMLElementEx(XMLType_e eType = e_XMLElement)
Constructs element, setting the type to eType.
[virtual]
XMLElementEx::~XMLElementEx()
Destructs the element.
void XMLElementEx::AddAttribute(XMLAttribute *pAttr)
Adds the attribute pAttr after all other attributes in this element.
See also XMLAttribute::SetNext and XMLAttribute::SetPrevious.
[virtual]
XMLElementEx *XMLElementEx::AddChild(const char *xml, unsigned int &nLineNumber, int level = 0)
Adds a child element (as last child) from the XML string provided in xml. Returns pointer to inserted element, or nullptr if some error occurred.
[virtual]
XMLElementEx *XMLElementEx::AddChild(const std::string &xml, unsigned int &linenumber, int level = 0)
Adds a child element (as last child) from the XML string provided in xml. Returns pointer to inserted element, or nullptr if some error occurred.
[virtual]
bool XMLElementEx::Dump(FILE *pFile)
Reimplemented from XMLPrimitive::Dump().
Appends this element, all attributes and child-elements to pFile.
[virtual]
char *XMLElementEx::Dump(char *pzBuffer)
Reimplemented from XMLPrimitive::Dump().
Appends the content of this element including attributes and child-elements to pzBuffer.
See also GetWriteBufferSize().
[virtual]
void XMLElementEx::Dump(XMLBuffer &strBuffer)
Reimplemented from XMLPrimitive::Dump().
Appends the content of this element including attributes and child-elements to strBuffer.
XMLAttribute *XMLElementEx::FindAttribute(const char *pzName)
Returns the first XMLAttribute matching pzName, or nullptr if not found.
XMLAttribute *XMLElementEx::FindAttribute(const std::string &name)
Returns the first XMLAttribute matching name, or nullptr if not found.
XMLAttribute *XMLElementEx::GetAttribute()
Gets the first attribute in the element, or nullptr if not found.
bool XMLElementEx::GetAttribute(const std::string &attrName, std::string &attrValue)
Gets the value of the attribute attrName into attrValue.
XMLString XMLElementEx::GetAttributeValue(const char *pzName)
Gets the first attribute value matching pzName, or nullptr if not found.
std::string XMLElementEx::GetAttributeValue(const std::string &name)
Gets the first attribute value matching name or empty string if not found.
XMLElementEx *XMLElementEx::GetChild(const char *pzName = NULL) const
Gets the first child element of type XMLElementEx with pzName, or nullptr if none.
XMLElementEx *XMLElementEx::GetChild(const std::string &name) const
Gets the first child element matching name.
[virtual]
bool XMLElementEx::GetChildElement(const std::string &name, XMLElementEx *&pReturnChild)
Gets the first child element matching name and returns it in the supplied pReturnChild. Returns true if successful
XMLElementEx *XMLElementEx::GetNext(const char *pzName = NULL) const
Gets the next XMLPrimitive of type XMLElementEx with pzName at this level, or nullptr if none.
XMLElementEx *XMLElementEx::GetPrevious(const char *pzName = NULL) const
Gets the previous XML primitive of type XMLElementEx with pzName at this level, or nullptr if none.
std::string XMLElementEx::GetStrValue() const
Gets the element value as std::string.
const XMLString &XMLElementEx::GetValue() const
Gets the element value.
[virtual]
unsigned int XMLElementEx::GetWriteBufferSize()
Reimplemented from XMLPrimitive::GetWriteBufferSize().
Gets the size to allocate for this item, children and next items.
bool XMLElementEx::HasAttribute(const std::string &attrName)
Checks if the element has an attribute with the name 'attrName'.
bool XMLElementEx::HasChildElement(const std::string &name)
Returns true if the child element matching name is found.
[virtual]
void XMLElementEx::Merge(XMLPrimitive *pOther)
Reimplemented from XMLPrimitive::Merge().
Merges data from pOther into this element by adding attributes and children that don't exist in this element but do exist in pOther into this element.
[virtual]
const char *XMLElementEx::Parse(const char *pStart, unsigned int &nLineNumber)
Reimplemented from XMLPrimitive::Parse().
Parses XML Element , all attributes and all children. Returns traversed pStart char* pointing to text after this element, or nullptr.
void XMLElementEx::RemoveChild(const std::string &elementName, const std::string &name)
Removes a child element named elementName with attribute "Name" having value name from the XML.
void XMLElementEx::SetAttribute(XMLAttribute *pAtt)
Sets/overwrites the first attribute in this element with pAtt.
void XMLElementEx::SetAttributeValue(const char *attributeName, const char *attributeValue)
Sets the attribute attributeName to attributeValue, creating it if it does not exist.
void XMLElementEx::SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
Sets the attribute attributeName to attributeValue, creating it if it does not exist.
void XMLElementEx::SetStrValue(const std::string &value)
Sets the element value to value.
void XMLElementEx::SetValue(XMLString newValue)
Sets the element value to newValue.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.