99 XmlElement (String::CharPointerType tagNameBegin, String::CharPointerType tagNameEnd);
129 bool ignoreOrderOfAttributes)
const noexcept;
143 bool addDefaultHeader =
true;
144 int lineWrapLength = 60;
145 const char* newLineChars =
"\r\n";
148 [[nodiscard]]
TextFormat withoutHeader()
const;
161 void writeTo (
OutputStream& output,
const TextFormat& format = {})
const;
166 bool writeTo (
const File& destinationFile,
const TextFormat& format = {})
const;
176 String getNamespace()
const;
179 String getTagNameWithoutNamespace()
const;
185 bool hasTagName (
StringRef possibleTagName)
const noexcept;
191 bool hasTagNameIgnoringNamespace (
StringRef possibleTagName)
const;
204 int getNumAttributes() const noexcept;
213 const
String& getAttributeName (
int attributeIndex) const noexcept;
222 const
String& getAttributeValue (
int attributeIndex) const noexcept;
228 bool hasAttribute (
StringRef attributeName) const noexcept;
233 const
String& getStringAttribute (
StringRef attributeName) const noexcept;
250 bool compareAttribute (
StringRef attributeName,
252 bool ignoreCase = false) const noexcept;
264 int getIntAttribute (
StringRef attributeName,
int defaultReturnValue = 0) const;
276 double getDoubleAttribute (
StringRef attributeName,
double defaultReturnValue = 0.0) const;
288 bool getBoolAttribute (
StringRef attributeName,
bool defaultReturnValue = false) const;
303 void setAttribute (const
Identifier& attributeName, const
String& newValue);
317 void setAttribute (const
Identifier& attributeName,
int newValue);
331 void setAttribute (const
Identifier& attributeName,
double newValue);
338 void removeAttribute (const
Identifier& attributeName) noexcept;
341 void removeAllAttributes() noexcept;
351 XmlElement* getFirstChildElement() const noexcept {
return firstChildElement; }
394 int getNumChildElements() const noexcept;
404 XmlElement* getChildElement (
int index) const noexcept;
422 StringRef attributeValue) const noexcept;
438 void addChildElement (
XmlElement* newChildElement) noexcept;
451 void insertChildElement (
XmlElement* newChildElement,
452 int indexToInsertAt) noexcept;
466 void prependChildElement (
XmlElement* newChildElement) noexcept;
491 bool replaceChildElement (
XmlElement* currentChildElement,
500 void removeChildElement (
XmlElement* childToRemove,
501 bool shouldDeleteTheChild) noexcept;
506 void deleteAllChildElements() noexcept;
511 void deleteAllChildElementsWithTagName (
StringRef tagName) noexcept;
514 bool containsChildElement (const
XmlElement* possibleChild) const noexcept;
551 template <class ElementComparator>
552 void sortChildElements (ElementComparator& comparator,
553 bool retainOrderOfEquivalentItems = false)
555 auto num = getNumChildElements();
560 getChildElementsAsArray (elems);
561 sortArray (comparator, (
XmlElement**) elems, 0, num - 1, retainOrderOfEquivalentItems);
562 reorderChildElements (elems, num);
574 bool isTextElement() const noexcept;
592 const
String& getText() const noexcept;
600 void setText (const
String& newText);
615 String getAllSubText() const;
626 const
String& defaultReturnValue) const;
631 void addTextElement (const
String& text);
636 void deleteAllTextElements() noexcept;
642 static
bool isValidXmlName (
StringRef possibleName) noexcept;
646 struct GetNextElement
651 struct GetNextElementWithTagName
653 GetNextElementWithTagName() =
default;
654 explicit GetNextElementWithTagName (String n) : name (std::move (n)) {}
655 XmlElement* getNext (
const XmlElement& e)
const {
return e.getNextElementWithTagName (name); }
661 template <
typename Traits>
662 class Iterator :
private Traits
665 using difference_type = ptrdiff_t;
666 using value_type = XmlElement*;
667 using pointer =
const value_type*;
668 using reference = value_type;
669 using iterator_category = std::input_iterator_tag;
671 Iterator() =
default;
673 template <
typename... Args>
674 Iterator (XmlElement* e, Args&&... args)
675 : Traits (std::forward<Args> (args)...), element (e) {}
677 Iterator begin()
const {
return *
this; }
678 Iterator end()
const {
return Iterator{}; }
680 bool operator== (
const Iterator& other)
const {
return element == other.element; }
681 bool operator!= (
const Iterator& other)
const {
return ! operator== (other); }
683 reference operator*()
const {
return element; }
684 pointer operator->()
const {
return &element; }
686 Iterator& operator++()
688 element = Traits::getNext (*element);
692 Iterator operator++ (
int)
700 value_type element =
nullptr;
717 return Iterator<GetNextElement> { getFirstChildElement() };
732 return Iterator<GetNextElementWithTagName> { getChildByName (name), name };
736 [[deprecated]]
void macroBasedForLoop() const noexcept {}
738 [[deprecated (
"This has been deprecated in favour of the toString method.")]]
739 String createDocument (StringRef dtdToUse,
740 bool allOnOneLine =
false,
741 bool includeXmlHeader =
true,
742 StringRef encodingType =
"UTF-8",
743 int lineWrapLength = 60)
const;
745 [[deprecated (
"This has been deprecated in favour of the writeTo method.")]]
746 void writeToStream (OutputStream& output,
748 bool allOnOneLine =
false,
749 bool includeXmlHeader =
true,
750 StringRef encodingType =
"UTF-8",
751 int lineWrapLength = 60)
const;
753 [[deprecated (
"This has been deprecated in favour of the writeTo method.")]]
754 bool writeToFile (
const File& destinationFile,
756 StringRef encodingType =
"UTF-8",
757 int lineWrapLength = 60)
const;
762 struct XmlAttributeNode
764 XmlAttributeNode (
const XmlAttributeNode&)
noexcept;
765 XmlAttributeNode (
const Identifier&,
const String&)
noexcept;
766 XmlAttributeNode (String::CharPointerType, String::CharPointerType);
768 LinkedListPointer<XmlAttributeNode> nextListItem;
773 XmlAttributeNode& operator= (
const XmlAttributeNode&) =
delete;
776 friend class XmlDocument;
777 friend class LinkedListPointer<XmlAttributeNode>;
778 friend class LinkedListPointer<XmlElement>;
779 friend class LinkedListPointer<XmlElement>::Appender;
780 friend class NamedValueSet;
782 LinkedListPointer<XmlElement> nextListItem, firstChildElement;
783 LinkedListPointer<XmlAttributeNode> attributes;
786 XmlElement (int) noexcept;
787 void copyChildrenAndAttributesFrom (const XmlElement&);
788 void writeElementAsText (OutputStream&, int, int, const char*) const;
789 void getChildElementsAsArray (XmlElement**) const noexcept;
790 void reorderChildElements (XmlElement**, int) noexcept;
791 XmlAttributeNode* getAttribute (StringRef) const noexcept;
796 XmlElement (const wchar_t*) = delete;
798 JUCE_LEAK_DETECTOR (XmlElement)
824#define forEachXmlChildElement(parentXmlElement, childElementVariableName) \
825 for (auto* (childElementVariableName) : ((parentXmlElement).macroBasedForLoop(), (parentXmlElement).getChildIterator()))
852#define forEachXmlChildElementWithTagName(parentXmlElement, childElementVariableName, requiredTagName) \
853 for (auto* (childElementVariableName) : ((parentXmlElement).macroBasedForLoop(), (parentXmlElement).getChildWithTagNameIterator ((requiredTagName))))
XmlElement * getNextElement() const noexcept
Iterator< GetNextElementWithTagName > getChildWithTagNameIterator(StringRef name) const
Iterator< GetNextElement > getChildIterator() const
const String & getTagName() const noexcept