OpenShot Library | libopenshot-audio
0.1.9
|
Used to build a tree of elements representing an XML document. More...
#include <juce_XmlElement.h>
Public Member Functions | |
XmlElement (const String &tagName) | |
Creates an XmlElement with this tag name. More... | |
XmlElement (const char *tagName) | |
Creates an XmlElement with this tag name. More... | |
XmlElement (const Identifier &tagName) | |
Creates an XmlElement with this tag name. More... | |
XmlElement (StringRef tagName) | |
Creates an XmlElement with this tag name. More... | |
XmlElement (String::CharPointerType tagNameBegin, String::CharPointerType tagNameEnd) | |
Creates an XmlElement with this tag name. More... | |
XmlElement (const XmlElement &) | |
Creates a (deep) copy of another element. More... | |
XmlElement & | operator= (const XmlElement &) |
Creates a (deep) copy of another element. More... | |
XmlElement & | operator= (XmlElement &&) noexcept |
Move assignment operator. | |
XmlElement (XmlElement &&) noexcept | |
Move constructor. | |
~XmlElement () noexcept | |
Deleting an XmlElement will also delete all of its child elements. More... | |
bool | isEquivalentTo (const XmlElement *other, bool ignoreOrderOfAttributes) const noexcept |
Compares two XmlElements to see if they contain the same text and attributes. More... | |
String | createDocument (StringRef dtdToUse, bool allOnOneLine=false, bool includeXmlHeader=true, StringRef encodingType="UTF-8", int lineWrapLength=60) const |
Returns an XML text document that represents this element. More... | |
void | writeToStream (OutputStream &output, StringRef dtdToUse, bool allOnOneLine=false, bool includeXmlHeader=true, StringRef encodingType="UTF-8", int lineWrapLength=60) const |
Writes the document to a stream as UTF-8. More... | |
bool | writeToFile (const File &destinationFile, StringRef dtdToUse, StringRef encodingType="UTF-8", int lineWrapLength=60) const |
Writes the element to a file as an XML document. More... | |
const String & | getTagName () const noexcept |
Returns this element's tag type name. More... | |
String | getNamespace () const |
Returns the namespace portion of the tag-name, or an empty string if none is specified. More... | |
String | getTagNameWithoutNamespace () const |
Returns the part of the tag-name that follows any namespace declaration. More... | |
bool | hasTagName (StringRef possibleTagName) const noexcept |
Tests whether this element has a particular tag name. More... | |
bool | hasTagNameIgnoringNamespace (StringRef possibleTagName) const |
Tests whether this element has a particular tag name, ignoring any XML namespace prefix. More... | |
void | setTagName (StringRef newTagName) |
Changes this elements tag name. More... | |
int | getNumAttributes () const noexcept |
Returns the number of XML attributes this element contains. More... | |
const String & | getAttributeName (int attributeIndex) const noexcept |
Returns the name of one of the elements attributes. More... | |
const String & | getAttributeValue (int attributeIndex) const noexcept |
Returns the value of one of the elements attributes. More... | |
bool | hasAttribute (StringRef attributeName) const noexcept |
Checks whether the element contains an attribute with a certain name. More... | |
const String & | getStringAttribute (StringRef attributeName) const noexcept |
Returns the value of a named attribute. More... | |
String | getStringAttribute (StringRef attributeName, const String &defaultReturnValue) const |
Returns the value of a named attribute. More... | |
bool | compareAttribute (StringRef attributeName, StringRef stringToCompareAgainst, bool ignoreCase=false) const noexcept |
Compares the value of a named attribute with a value passed-in. More... | |
int | getIntAttribute (StringRef attributeName, int defaultReturnValue=0) const |
Returns the value of a named attribute as an integer. More... | |
double | getDoubleAttribute (StringRef attributeName, double defaultReturnValue=0.0) const |
Returns the value of a named attribute as floating-point. More... | |
bool | getBoolAttribute (StringRef attributeName, bool defaultReturnValue=false) const |
Returns the value of a named attribute as a boolean. More... | |
void | setAttribute (const Identifier &attributeName, const String &newValue) |
Adds a named attribute to the element. More... | |
void | setAttribute (const Identifier &attributeName, int newValue) |
Adds a named attribute to the element, setting it to an integer value. More... | |
void | setAttribute (const Identifier &attributeName, double newValue) |
Adds a named attribute to the element, setting it to a floating-point value. More... | |
void | removeAttribute (const Identifier &attributeName) noexcept |
Removes a named attribute from the element. More... | |
void | removeAllAttributes () noexcept |
Removes all attributes from this element. More... | |
XmlElement * | getFirstChildElement () const noexcept |
Returns the first of this element's sub-elements. More... | |
XmlElement * | getNextElement () const noexcept |
Returns the next of this element's siblings. More... | |
XmlElement * | getNextElementWithTagName (StringRef requiredTagName) const |
Returns the next of this element's siblings which has the specified tag name. More... | |
int | getNumChildElements () const noexcept |
Returns the number of sub-elements in this element. More... | |
XmlElement * | getChildElement (int index) const noexcept |
Returns the sub-element at a certain index. More... | |
XmlElement * | getChildByName (StringRef tagNameToLookFor) const noexcept |
Returns the first sub-element with a given tag-name. More... | |
XmlElement * | getChildByAttribute (StringRef attributeName, StringRef attributeValue) const noexcept |
Returns the first sub-element which has an attribute that matches the given value. More... | |
void | addChildElement (XmlElement *newChildElement) noexcept |
Appends an element to this element's list of children. More... | |
void | insertChildElement (XmlElement *newChildElement, int indexToInsertAt) noexcept |
Inserts an element into this element's list of children. More... | |
void | prependChildElement (XmlElement *newChildElement) noexcept |
Inserts an element at the beginning of this element's list of children. More... | |
XmlElement * | createNewChildElement (StringRef tagName) |
Creates a new element with the given name and returns it, after adding it as a child element. More... | |
bool | replaceChildElement (XmlElement *currentChildElement, XmlElement *newChildNode) noexcept |
Replaces one of this element's children with another node. More... | |
void | removeChildElement (XmlElement *childToRemove, bool shouldDeleteTheChild) noexcept |
Removes a child element. More... | |
void | deleteAllChildElements () noexcept |
Deletes all the child elements in the element. More... | |
void | deleteAllChildElementsWithTagName (StringRef tagName) noexcept |
Deletes all the child elements with a given tag name. More... | |
bool | containsChildElement (const XmlElement *possibleChild) const noexcept |
Returns true if the given element is a child of this one. More... | |
XmlElement * | findParentElementOf (const XmlElement *childToSearchFor) noexcept |
Recursively searches all sub-elements of this one, looking for an element which is the direct parent of the specified element. More... | |
template<class ElementComparator > | |
void | sortChildElements (ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) |
Sorts the child elements using a comparator. More... | |
bool | isTextElement () const noexcept |
Returns true if this element is a section of text. More... | |
const String & | getText () const noexcept |
Returns the text for a text element. More... | |
void | setText (const String &newText) |
Sets the text in a text element. More... | |
String | getAllSubText () const |
Returns all the text from this element's child nodes. More... | |
String | getChildElementAllSubText (StringRef childTagName, const String &defaultReturnValue) const |
Returns all the sub-text of a named child element. More... | |
void | addTextElement (const String &text) |
Appends a section of text to this element. More... | |
void | deleteAllTextElements () noexcept |
Removes all the text elements from this element. More... | |
Static Public Member Functions | |
static XmlElement * | createTextElement (const String &text) |
Creates a text element that can be added to a parent element. More... | |
static bool | isValidXmlName (StringRef possibleName) noexcept |
Checks if a given string is a valid XML name. | |
Friends | |
class | XmlDocument |
class | LinkedListPointer< XmlAttributeNode > |
class | LinkedListPointer< XmlElement > |
class | LinkedListPointer< XmlElement >::Appender |
class | NamedValueSet |
Used to build a tree of elements representing an XML document.
An XML document can be parsed into a tree of XmlElements, each of which represents an XML tag structure, and which may itself contain other nested elements.
An XmlElement can also be converted back into a text document, and has lots of useful methods for manipulating its attributes and sub-elements, so XmlElements can actually be used as a handy general-purpose data structure.
Here's an example of parsing some elements:
And here's an example of how to create an XML document from scratch:
Definition at line 141 of file juce_XmlElement.h.
|
explicit |
Creates an XmlElement with this tag name.
Definition at line 76 of file juce_XmlElement.cpp.
References isValidXmlName().
Referenced by createNewChildElement(), createTextElement(), and XmlElement().
|
explicit |
Creates an XmlElement with this tag name.
Definition at line 82 of file juce_XmlElement.cpp.
References isValidXmlName().
|
explicit |
Creates an XmlElement with this tag name.
Definition at line 94 of file juce_XmlElement.cpp.
References isValidXmlName().
|
explicit |
Creates an XmlElement with this tag name.
Definition at line 88 of file juce_XmlElement.cpp.
References isValidXmlName().
juce::XmlElement::XmlElement | ( | String::CharPointerType | tagNameBegin, |
String::CharPointerType | tagNameEnd | ||
) |
Creates an XmlElement with this tag name.
Definition at line 100 of file juce_XmlElement.cpp.
References isValidXmlName(), and XmlElement().
juce::XmlElement::XmlElement | ( | const XmlElement & | other | ) |
Creates a (deep) copy of another element.
Definition at line 110 of file juce_XmlElement.cpp.
|
noexcept |
Deleting an XmlElement will also delete all of its child elements.
Definition at line 161 of file juce_XmlElement.cpp.
References juce::LinkedListPointer< ObjectType >::deleteAll(), juce::CharPointer_UTF8::getAndAdvance(), juce::String::getCharPointer(), juce::OutputStream::getPosition(), getText(), isTextElement(), juce::OutputStream::write(), juce::OutputStream::writeByte(), and juce::OutputStream::writeRepeatedByte().
XmlElement & juce::XmlElement::operator= | ( | const XmlElement & | other | ) |
Creates a (deep) copy of another element.
Definition at line 116 of file juce_XmlElement.cpp.
References deleteAllChildElements(), and removeAllAttributes().
|
noexcept |
Compares two XmlElements to see if they contain the same text and attributes.
The elements are only considered equivalent if they contain the same attributes with the same values, and have the same sub-nodes.
other | the other element to compare to |
ignoreOrderOfAttributes | if true, this means that two elements with the same attributes in a different order will be considered the same; if false, the attributes must be in the same order as well |
Definition at line 707 of file juce_XmlElement.cpp.
References compareAttribute(), juce::LinkedListPointer< ObjectType >::get(), and getNumAttributes().
String juce::XmlElement::createDocument | ( | StringRef | dtdToUse, |
bool | allOnOneLine = false , |
||
bool | includeXmlHeader = true , |
||
StringRef | encodingType = "UTF-8" , |
||
int | lineWrapLength = 60 |
||
) | const |
Returns an XML text document that represents this element.
The string returned can be parsed to recreate the same XmlElement that was used to create it.
dtdToUse | the DTD to add to the document |
allOnOneLine | if true, this means that the document will not contain any linefeeds, so it'll be smaller but not very easy to read. |
includeXmlHeader | whether to add the "<?xml version..etc" line at the start of the document |
encodingType | the character encoding format string to put into the xml header |
lineWrapLength | the line length that will be used before items get placed on a new line. This isn't an absolute maximum length, it just determines how lists of attributes get broken up |
Definition at line 340 of file juce_XmlElement.cpp.
References juce::MemoryOutputStream::toUTF8(), and writeToStream().
Referenced by juce::PropertySet::setValue(), and juce::NetworkServiceDiscovery::Advertiser::~Advertiser().
void juce::XmlElement::writeToStream | ( | OutputStream & | output, |
StringRef | dtdToUse, | ||
bool | allOnOneLine = false , |
||
bool | includeXmlHeader = true , |
||
StringRef | encodingType = "UTF-8" , |
||
int | lineWrapLength = 60 |
||
) | const |
Writes the document to a stream as UTF-8.
output | the stream to write to |
dtdToUse | the DTD to add to the document |
allOnOneLine | if true, this means that the document will not contain any linefeeds, so it'll be smaller but not very easy to read. |
includeXmlHeader | whether to add the "<?xml version..etc" line at the start of the document |
encodingType | the character encoding format string to put into the xml header |
lineWrapLength | the line length that will be used before items get placed on a new line. This isn't an absolute maximum length, it just determines how lists of attributes get broken up |
Definition at line 352 of file juce_XmlElement.cpp.
References juce::StringRef::isNotEmpty(), and juce::OutputStream::writeByte().
Referenced by createDocument(), and writeToFile().
bool juce::XmlElement::writeToFile | ( | const File & | destinationFile, |
StringRef | dtdToUse, | ||
StringRef | encodingType = "UTF-8" , |
||
int | lineWrapLength = 60 |
||
) | const |
Writes the element to a file as an XML document.
To improve safety in case something goes wrong while writing the file, this will actually write the document to a new temporary file in the same directory as the destination file, and if this succeeds, it will rename this new file as the destination file (overwriting any existing file that was there).
destinationFile | the file to write to. If this already exists, it will be overwritten. |
dtdToUse | the DTD to add to the document |
encodingType | the character encoding format string to put into the xml header |
lineWrapLength | the line length that will be used before items get placed on a new line. This isn't an absolute maximum length, it just determines how lists of attributes get broken up |
Definition at line 384 of file juce_XmlElement.cpp.
References juce::TemporaryFile::getFile(), juce::TemporaryFile::overwriteTargetFileWithTemporary(), and writeToStream().
Referenced by juce::PropertiesFile::save().
|
inlinenoexcept |
Returns this element's tag type name.
E.g. for an element such as <MOOSE legs="4" antlers="2">, this would return "MOOSE".
Definition at line 265 of file juce_XmlElement.h.
Referenced by juce::ValueTree::fromXml(), and juce::XmlDocument::getLastParseError().
String juce::XmlElement::getNamespace | ( | ) | const |
Returns the namespace portion of the tag-name, or an empty string if none is specified.
Definition at line 417 of file juce_XmlElement.cpp.
References juce::String::upToFirstOccurrenceOf().
String juce::XmlElement::getTagNameWithoutNamespace | ( | ) | const |
Returns the part of the tag-name that follows any namespace declaration.
Definition at line 422 of file juce_XmlElement.cpp.
References juce::String::fromLastOccurrenceOf().
Referenced by hasTagNameIgnoringNamespace().
|
noexcept |
Tests whether this element has a particular tag name.
possibleTagName | the tag name you're comparing it with |
Definition at line 406 of file juce_XmlElement.cpp.
Referenced by hasTagNameIgnoringNamespace(), juce::AudioDeviceManager::initialise(), and juce::ChannelRemappingAudioSource::restoreFromXml().
bool juce::XmlElement::hasTagNameIgnoringNamespace | ( | StringRef | possibleTagName | ) | const |
Tests whether this element has a particular tag name, ignoring any XML namespace prefix.
So a test for e.g. "xyz" will return true for "xyz" and also "foo:xyz", "bar::xyz", etc.
Definition at line 427 of file juce_XmlElement.cpp.
References getTagNameWithoutNamespace(), and hasTagName().
void juce::XmlElement::setTagName | ( | StringRef | newTagName | ) |
Changes this elements tag name.
Definition at line 442 of file juce_XmlElement.cpp.
References juce::StringPool::getGlobalPool(), juce::StringPool::getPooledString(), and isValidXmlName().
|
noexcept |
Returns the number of XML attributes this element contains.
E.g. for an element such as <MOOSE legs="4" antlers="2">, this would return 2.
Definition at line 449 of file juce_XmlElement.cpp.
Referenced by isEquivalentTo().
|
noexcept |
Returns the name of one of the elements attributes.
E.g. for an element such as <MOOSE legs="4" antlers="2">, then getAttributeName(1) would return "antlers".
Definition at line 460 of file juce_XmlElement.cpp.
|
noexcept |
Returns the value of one of the elements attributes.
E.g. for an element such as <MOOSE legs="4" antlers="2">, then getAttributeName(1) would return "2".
Definition at line 468 of file juce_XmlElement.cpp.
|
noexcept |
Checks whether the element contains an attribute with a certain name.
Definition at line 485 of file juce_XmlElement.cpp.
Referenced by juce::AudioDeviceManager::initialise().
Returns the value of a named attribute.
attributeName | the name of the attribute to look up |
Definition at line 491 of file juce_XmlElement.cpp.
Referenced by juce::NetworkServiceDiscovery::AvailableServiceList::getServices(), getText(), juce::AudioDeviceManager::initialise(), and juce::ChannelRemappingAudioSource::restoreFromXml().
String juce::XmlElement::getStringAttribute | ( | StringRef | attributeName, |
const String & | defaultReturnValue | ||
) | const |
Returns the value of a named attribute.
attributeName | the name of the attribute to look up |
defaultReturnValue | a value to return if the element doesn't have an attribute with this name |
Definition at line 499 of file juce_XmlElement.cpp.
|
noexcept |
Compares the value of a named attribute with a value passed-in.
attributeName | the name of the attribute to look up |
stringToCompareAgainst | the value to compare it with |
ignoreCase | whether the comparison should be case-insensitive |
Definition at line 539 of file juce_XmlElement.cpp.
Referenced by isEquivalentTo().
int juce::XmlElement::getIntAttribute | ( | StringRef | attributeName, |
int | defaultReturnValue = 0 |
||
) | const |
Returns the value of a named attribute as an integer.
This will try to find the attribute and convert it to an integer (using the String::getIntValue() method).
attributeName | the name of the attribute to look up |
defaultReturnValue | a value to return if the element doesn't have an attribute with this name |
Definition at line 507 of file juce_XmlElement.cpp.
Referenced by juce::NetworkServiceDiscovery::AvailableServiceList::getServices(), and juce::AudioDeviceManager::initialise().
double juce::XmlElement::getDoubleAttribute | ( | StringRef | attributeName, |
double | defaultReturnValue = 0.0 |
||
) | const |
Returns the value of a named attribute as floating-point.
This will try to find the attribute and convert it to a double (using the String::getDoubleValue() method).
attributeName | the name of the attribute to look up |
defaultReturnValue | a value to return if the element doesn't have an attribute with this name |
Definition at line 515 of file juce_XmlElement.cpp.
Referenced by juce::AudioDeviceManager::initialise().
bool juce::XmlElement::getBoolAttribute | ( | StringRef | attributeName, |
bool | defaultReturnValue = false |
||
) | const |
Returns the value of a named attribute as a boolean.
This will try to find the attribute and interpret it as a boolean. To do this, it'll return true if the value is "1", "true", "y", etc, or false for other values.
attributeName | the name of the attribute to look up |
defaultReturnValue | a value to return if the element doesn't have an attribute with this name |
Definition at line 523 of file juce_XmlElement.cpp.
void juce::XmlElement::setAttribute | ( | const Identifier & | attributeName, |
const String & | newValue | ||
) |
Adds a named attribute to the element.
If the element already contains an attribute with this name, it's value will be updated to the new value. If there's no such attribute yet, a new one will be added.
Note that there are other setAttribute() methods that take integers, doubles, etc. to make it easy to store numbers.
attributeName | the name of the attribute to set |
newValue | the value to set it to |
Definition at line 551 of file juce_XmlElement.cpp.
Referenced by juce::NetworkServiceDiscovery::Advertiser::Advertiser(), juce::NamedValueSet::copyToXmlAttributes(), juce::ChannelRemappingAudioSource::createXml(), juce::PropertySet::createXml(), juce::PropertiesFile::save(), setAttribute(), setText(), and juce::NetworkServiceDiscovery::Advertiser::~Advertiser().
void juce::XmlElement::setAttribute | ( | const Identifier & | attributeName, |
int | newValue | ||
) |
Adds a named attribute to the element, setting it to an integer value.
If the element already contains an attribute with this name, it's value will be updated to the new value. If there's no such attribute yet, a new one will be added.
Note that there are other setAttribute() methods that take integers, doubles, etc. to make it easy to store numbers.
attributeName | the name of the attribute to set |
newValue | the value to set it to |
Definition at line 576 of file juce_XmlElement.cpp.
References setAttribute().
void juce::XmlElement::setAttribute | ( | const Identifier & | attributeName, |
double | newValue | ||
) |
Adds a named attribute to the element, setting it to a floating-point value.
If the element already contains an attribute with this name, it's value will be updated to the new value. If there's no such attribute yet, a new one will be added.
Note that there are other setAttribute() methods that take integers, doubles, etc. to make it easy to store numbers.
attributeName | the name of the attribute to set |
newValue | the value to set it to |
Definition at line 581 of file juce_XmlElement.cpp.
References setAttribute().
|
noexcept |
Removes a named attribute from the element.
attributeName | the name of the attribute to remove |
Definition at line 586 of file juce_XmlElement.cpp.
|
noexcept |
Removes all attributes from this element.
Definition at line 598 of file juce_XmlElement.cpp.
Referenced by operator=().
|
inlinenoexcept |
Returns the first of this element's sub-elements.
see getNextElement() for an example of how to iterate the sub-elements.
Definition at line 442 of file juce_XmlElement.h.
|
inlinenoexcept |
Returns the next of this element's siblings.
This can be used for iterating an element's sub-elements, e.g.
Note that when iterating the child elements, some of them might be text elements as well as XML tags - use isTextElement() to work this out.
Also, it's much easier and neater to use this method indirectly via the forEachXmlChildElement macro.
Definition at line 470 of file juce_XmlElement.h.
XmlElement * juce::XmlElement::getNextElementWithTagName | ( | StringRef | requiredTagName | ) | const |
Returns the next of this element's siblings which has the specified tag name.
This is like getNextElement(), but will scan through the list until it finds an element with the given tag name.
Definition at line 432 of file juce_XmlElement.cpp.
|
noexcept |
Returns the number of sub-elements in this element.
Definition at line 604 of file juce_XmlElement.cpp.
Referenced by getAllSubText().
|
noexcept |
Returns the sub-element at a certain index.
It's not very efficient to iterate the sub-elements by index - see getNextElement() for an example of how best to iterate.
Definition at line 609 of file juce_XmlElement.cpp.
|
noexcept |
Returns the first sub-element with a given tag-name.
tagNameToLookFor | the tag name of the element you want to find |
Definition at line 614 of file juce_XmlElement.cpp.
Referenced by getChildElementAllSubText().
|
noexcept |
Returns the first sub-element which has an attribute that matches the given value.
attributeName | the name of the attribute to check |
attributeValue | the target value of the attribute |
Definition at line 625 of file juce_XmlElement.cpp.
References juce::StringRef::isEmpty().
|
noexcept |
Appends an element to this element's list of children.
Child elements are deleted automatically when their parent is deleted, so make sure the object that you pass in will not be deleted by anything else, and make sure it's not already the child of another element.
Note that due to the XmlElement using a singly-linked-list, prependChildElement() is an O(1) operation, but addChildElement() is an O(N) operation - so if you're adding large number of elements, you may prefer to do so in reverse order!
Definition at line 636 of file juce_XmlElement.cpp.
Referenced by addTextElement(), and createNewChildElement().
|
noexcept |
Inserts an element into this element's list of children.
Child elements are deleted automatically when their parent is deleted, so make sure the object that you pass in will not be deleted by anything else, and make sure it's not already the child of another element.
newChildElement | the element to add |
indexToInsertAt | the index at which to insert the new element - if this is below zero, it will be added to the end of the list |
Definition at line 647 of file juce_XmlElement.cpp.
|
noexcept |
Inserts an element at the beginning of this element's list of children.
Child elements are deleted automatically when their parent is deleted, so make sure the object that you pass in will not be deleted by anything else, and make sure it's not already the child of another element.
Note that due to the XmlElement using a singly-linked-list, prependChildElement() is an O(1) operation, but addChildElement() is an O(N) operation - so if you're adding large number of elements, you may prefer to do so in reverse order!
Definition at line 658 of file juce_XmlElement.cpp.
XmlElement * juce::XmlElement::createNewChildElement | ( | StringRef | tagName | ) |
Creates a new element with the given name and returns it, after adding it as a child element.
This is a handy method that means that instead of writing this:
..you could just write this:
Definition at line 669 of file juce_XmlElement.cpp.
References addChildElement(), and XmlElement().
Referenced by juce::PropertySet::createXml(), and juce::PropertiesFile::save().
|
noexcept |
Replaces one of this element's children with another node.
If the current element passed-in isn't actually a child of this element, this will return false and the new one won't be added. Otherwise, the existing element will be deleted, replaced with the new one, and it will return true.
Definition at line 676 of file juce_XmlElement.cpp.
|
noexcept |
Removes a child element.
childToRemove | the child to look for and remove |
shouldDeleteTheChild | if true, the child will be deleted, if false it'll just remove it |
Definition at line 693 of file juce_XmlElement.cpp.
References containsChildElement().
Referenced by deleteAllChildElementsWithTagName(), and deleteAllTextElements().
|
noexcept |
Deletes all the child elements in the element.
Definition at line 780 of file juce_XmlElement.cpp.
Referenced by operator=().
|
noexcept |
Deletes all the child elements with a given tag name.
Definition at line 785 of file juce_XmlElement.cpp.
References removeChildElement().
|
noexcept |
Returns true if the given element is a child of this one.
Definition at line 798 of file juce_XmlElement.cpp.
Referenced by removeChildElement().
|
noexcept |
Recursively searches all sub-elements of this one, looking for an element which is the direct parent of the specified element.
Because elements don't store a pointer to their parent, if you have one and need to find its parent, the only way to do so is to exhaustively search the whole tree for it.
If the given child is found somewhere in this element's hierarchy, then this method will return its parent. If not, it will return nullptr.
Definition at line 803 of file juce_XmlElement.cpp.
|
inline |
Sorts the child elements using a comparator.
This will use a comparator object to sort the elements into order. The object passed must have a method of the form:
..and this method must return:
To improve performance, the compareElements() method can be declared as static or const.
comparator | the comparator to use for comparing elements. |
retainOrderOfEquivalentItems | if this is true, then items which the comparator says are equivalent will be kept in the order in which they currently appear in the array. This is slower to perform, but may be important in some cases. If it's false, a faster algorithm is used, but equivalent elements may be rearranged. |
Definition at line 643 of file juce_XmlElement.h.
|
noexcept |
Returns true if this element is a section of text.
Elements can either be an XML tag element or a section of text, so this is used to find out what kind of element this one is.
Definition at line 840 of file juce_XmlElement.cpp.
Referenced by juce::ValueTree::fromXml(), getAllSubText(), getText(), setText(), and ~XmlElement().
|
noexcept |
Returns the text for a text element.
Note that if you have an element like this:
then calling getText on the "xyz" element won't return "hello", because that is actually stored in a special text sub-element inside the xyz element. To get the "hello" string, you could either call getText on the (unnamed) sub-element, or use getAllSubText() to do this automatically.
Note that leading and trailing whitespace will be included in the string - to remove if, just call String::trim() on the result.
Definition at line 847 of file juce_XmlElement.cpp.
References getStringAttribute(), and isTextElement().
Referenced by getAllSubText(), and ~XmlElement().
void juce::XmlElement::setText | ( | const String & | newText | ) |
Sets the text in a text element.
Note that this is only a valid call if this element is a text element. If it's not, then no action will be performed. If you're trying to add text inside a normal element, you probably want to use addTextElement() instead.
Definition at line 856 of file juce_XmlElement.cpp.
References isTextElement(), and setAttribute().
String juce::XmlElement::getAllSubText | ( | ) | const |
Returns all the text from this element's child nodes.
This iterates all the child elements and when it finds text elements, it concatenates their text into a big string which it returns.
E.g.
if you called getAllSubText on the "xyz" element, it'd return "hello there world".
Note that leading and trailing whitespace will be included in the string - to remove if, just call String::trim() on the result.
Definition at line 864 of file juce_XmlElement.cpp.
References getNumChildElements(), getText(), isTextElement(), and juce::MemoryOutputStream::toUTF8().
String juce::XmlElement::getChildElementAllSubText | ( | StringRef | childTagName, |
const String & | defaultReturnValue | ||
) | const |
Returns all the sub-text of a named child element.
If there is a child element with the given tag name, this will return all of its sub-text (by calling getAllSubText() on it). If there is no such child element, this will return the default string passed-in.
Definition at line 880 of file juce_XmlElement.cpp.
References getChildByName().
void juce::XmlElement::addTextElement | ( | const String & | text | ) |
Appends a section of text to this element.
Definition at line 910 of file juce_XmlElement.cpp.
References addChildElement(), and createTextElement().
|
noexcept |
Removes all the text elements from this element.
Definition at line 915 of file juce_XmlElement.cpp.
References removeChildElement().
|
static |
Creates a text element that can be added to a parent element.
Definition at line 888 of file juce_XmlElement.cpp.
References XmlElement().
Referenced by addTextElement(), and juce::XmlDocument::getLastParseError().