Added constructor and method allowing to copy an XML element from/to a NamedList.
git-svn-id: http://voip.null.ro/svn/yate@1944 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
5b1af73590
commit
40ee629193
|
@ -167,6 +167,28 @@ XMLElement::XMLElement(TiXmlElement* element, bool owner)
|
|||
// name(),m_owner,this);
|
||||
}
|
||||
|
||||
// Build this XML element from a list containing name, attributes and text.
|
||||
XMLElement::XMLElement(NamedList& src, const char* prefix)
|
||||
: m_type(Unknown), m_owner(true), m_element(0)
|
||||
{
|
||||
m_element = new TiXmlElement(src.getValue(prefix));
|
||||
DDebug(DebugAll,"XMLElement(%s) src=%s prefix=%s [%p]",
|
||||
m_name.c_str(),src.c_str(),prefix,this);
|
||||
String pref(String(prefix) + ".");
|
||||
// Set text
|
||||
const char* text = src.getValue(pref);
|
||||
if (text)
|
||||
m_element->LinkEndChild(new TiXmlText(text));
|
||||
// Add attributes
|
||||
unsigned int n = src.count();
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
NamedString* ns = src.getParam(i);
|
||||
if (ns && ns->name().startsWith(pref))
|
||||
setAttribute(ns->name().substr(pref.length()),*ns);
|
||||
}
|
||||
setType();
|
||||
}
|
||||
|
||||
XMLElement::~XMLElement()
|
||||
{
|
||||
if (m_owner && m_element)
|
||||
|
@ -185,6 +207,20 @@ void XMLElement::toString(String& dest, bool unclose) const
|
|||
}
|
||||
}
|
||||
|
||||
// Put this element's name, text and attributes to a list of parameters
|
||||
void XMLElement::toList(NamedList& dest, const char* prefix)
|
||||
{
|
||||
DDebug(DebugAll,"XMLElement(%s) to list=%s prefix=%s [%p]",
|
||||
m_name.c_str(),dest.c_str(),prefix,this);
|
||||
dest.addParam(prefix,name());
|
||||
String pref(String(prefix) + ".");
|
||||
const char* tmp = getText();
|
||||
if (tmp)
|
||||
dest.addParam(pref,tmp);
|
||||
for (const TiXmlAttribute* a = firstAttribute(); a; a = a->Next())
|
||||
dest.addParam(pref + a->Name(),a->Value());
|
||||
}
|
||||
|
||||
void XMLElement::setAttribute(const char* name, const char* value)
|
||||
{
|
||||
if (!(valid() && name && value))
|
||||
|
|
|
@ -163,6 +163,17 @@ public:
|
|||
*/
|
||||
XMLElement(Type type, NamedList* attributes = 0, const char* text = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Build this XML element from a list containing name, attributes and text.
|
||||
* Element's name must be a parameter whose name must be equal to prefix.
|
||||
* Element's text must be a parameter whose name is prefix followed by a dot.
|
||||
* The list of attributes will be built from parameters starting with prefix.attributename
|
||||
* @param src The list containing data used to build this XML element
|
||||
* @param prefix The prefix used to search the list of parameters
|
||||
*/
|
||||
XMLElement(NamedList& src, const char* prefix);
|
||||
|
||||
/**
|
||||
* Destructor. Deletes the underlying TiXmlElement if owned
|
||||
*/
|
||||
|
@ -211,6 +222,13 @@ public:
|
|||
*/
|
||||
void toString(String& dest, bool unclose = false) const;
|
||||
|
||||
/**
|
||||
* Put this element's name, text and attributes to a list of parameters
|
||||
* @param dest Destination list
|
||||
* @param prefix Prefix to add to parameters
|
||||
*/
|
||||
void toList(NamedList& dest, const char* prefix);
|
||||
|
||||
/**
|
||||
* Set the value of an existing attribute or adds a new one
|
||||
* @param name Attribute's name
|
||||
|
|
Loading…
Reference in New Issue