Browse Source

Added method XmlElement::getChildByAttribute().

tags/2021-05-28
jules 12 years ago
parent
commit
4198291d9a
2 changed files with 24 additions and 1 deletions
  1. +13
    -0
      modules/juce_core/xml/juce_XmlElement.cpp
  2. +11
    -1
      modules/juce_core/xml/juce_XmlElement.h

+ 13
- 0
modules/juce_core/xml/juce_XmlElement.cpp View File

@@ -562,6 +562,8 @@ XmlElement* XmlElement::getChildElement (const int index) const noexcept
XmlElement* XmlElement::getChildByName (StringRef childName) const noexcept
{
jassert (! childName.isEmpty());
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
if (child->hasTagName (childName))
return child;
@@ -569,6 +571,17 @@ XmlElement* XmlElement::getChildByName (StringRef childName) const noexcept
return nullptr;
}
XmlElement* XmlElement::getChildByAttribute (StringRef attributeName, StringRef attributeValue) const noexcept
{
jassert (! attributeName.isEmpty());
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
if (child->compareAttribute (attributeName, attributeValue))
return child;
return nullptr;
}
void XmlElement::addChildElement (XmlElement* const newNode) noexcept
{
if (newNode != nullptr)


+ 11
- 1
modules/juce_core/xml/juce_XmlElement.h View File

@@ -483,10 +483,20 @@ public:
@param tagNameToLookFor the tag name of the element you want to find
@returns the first element with this tag name, or nullptr if none is found
@see getNextElement, isTextElement, getChildElement
@see getNextElement, isTextElement, getChildElement, getChildByAttribute
*/
XmlElement* getChildByName (StringRef tagNameToLookFor) const noexcept;
/** Returns the first sub-element which has an attribute that matches the given value.
@param attributeName the name of the attribute to check
@param attributeValue the target value of the attribute
@returns the first element with this attribute value, or nullptr if none is found
@see getChildByName
*/
XmlElement* getChildByAttribute (StringRef attributeName,
StringRef attributeValue) const noexcept;
//==============================================================================
/** Appends an element to this element's list of children.


Loading…
Cancel
Save