Added setText() and setAttributes() functions to XmlElement class.

setText() allows replacing the text of an XmlElement.
setAttributes() allows setting multiple attributes from a NamedList.



git-svn-id: http://voip.null.ro/svn/yate@5650 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2013-09-12 08:40:58 +00:00
parent 959dafed80
commit e51f1d750f
2 changed files with 53 additions and 0 deletions

View File

@ -1839,6 +1839,26 @@ XmlChild* XmlElement::getFirstChild()
return static_cast<XmlChild*>(m_children.getChildren().skipNull()->get());
}
XmlText* XmlElement::setText(const char* text)
{
XmlText* txt = 0;
for (ObjList* o = getChildren().skipNull(); o; o = o->skipNext()) {
txt = (static_cast<XmlChild*>(o->get()))->xmlText();
if (txt)
break;
}
if (txt) {
if (!text)
return static_cast<XmlText*>(removeChild(txt));
txt->setText(text);
}
else if (text) {
txt = new XmlText(text);
addChild(txt);
}
return txt;
}
// Add a text child
void XmlElement::addText(const char* text)
{
@ -1948,6 +1968,14 @@ unsigned int XmlElement::copyAttributes(NamedList& list, const String& prefix) c
return copy;
}
void XmlElement::setAttributes(NamedList& list, const String& prefix, bool skipPrefix)
{
if (prefix)
m_element.copySubParams(list,prefix,skipPrefix);
else
m_element.copyParams(list);
}
// Retrieve a namespace attribute. Search in parent or inherited for it
String* XmlElement::xmlnsAttribute(const String& name) const
{

View File

@ -1372,6 +1372,15 @@ public:
*/
const String& getText() const;
/**
* Set text for first XmlText element found in this XmlElement's children
* If child text element does not exist, create it and append it to the element's children.
* @param text Text to set to the XmlElement. If null, the first found XmlText element
* will be deleted.
* @return The set XmlText if text was set, null if an XmlText was deleted
*/
XmlText* setText(const char* text);
/**
* Add a text child
* @param text Non empty text to add
@ -1393,6 +1402,15 @@ public:
*/
unsigned int copyAttributes(NamedList& list, const String& prefix) const;
/**
* Set element attributes from a list of parameters
* @param list List of attributes
* @param prefix Add only the attributes that start with this prefix. =
* If NULL, it will set as attributes the whole parameter list
* @param skipPrefix Skip over the prefix when building attribute name
*/
void setAttributes(NamedList& list, const String& prefix, bool skipPrefix = true);
/**
* Add or replace an attribute
* @param name Attribute name
@ -1697,6 +1715,13 @@ public:
inline const String& getText() const
{ return m_text; }
/**
* Set the text
* @param text Text to set in this XmlText
*/
inline void setText(const char* text)
{ m_text = text; }
/**
* Build a String from this XmlText
* @param dump The string where to append representation