The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

740 lines
31KB

  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef __JUCE_XMLELEMENT_JUCEHEADER__
  22. #define __JUCE_XMLELEMENT_JUCEHEADER__
  23. #include "../text/juce_String.h"
  24. #include "../streams/juce_OutputStream.h"
  25. #include "../files/juce_File.h"
  26. #include "../containers/juce_LinkedListPointer.h"
  27. //==============================================================================
  28. /** A handy macro to make it easy to iterate all the child elements in an XmlElement.
  29. The parentXmlElement should be a reference to the parent XML, and the childElementVariableName
  30. will be the name of a pointer to each child element.
  31. E.g. @code
  32. XmlElement* myParentXml = createSomeKindOfXmlDocument();
  33. forEachXmlChildElement (*myParentXml, child)
  34. {
  35. if (child->hasTagName ("FOO"))
  36. doSomethingWithXmlElement (child);
  37. }
  38. @endcode
  39. @see forEachXmlChildElementWithTagName
  40. */
  41. #define forEachXmlChildElement(parentXmlElement, childElementVariableName) \
  42. \
  43. for (juce::XmlElement* childElementVariableName = (parentXmlElement).getFirstChildElement(); \
  44. childElementVariableName != nullptr; \
  45. childElementVariableName = childElementVariableName->getNextElement())
  46. /** A macro that makes it easy to iterate all the child elements of an XmlElement
  47. which have a specified tag.
  48. This does the same job as the forEachXmlChildElement macro, but only for those
  49. elements that have a particular tag name.
  50. The parentXmlElement should be a reference to the parent XML, and the childElementVariableName
  51. will be the name of a pointer to each child element. The requiredTagName is the
  52. tag name to match.
  53. E.g. @code
  54. XmlElement* myParentXml = createSomeKindOfXmlDocument();
  55. forEachXmlChildElementWithTagName (*myParentXml, child, "MYTAG")
  56. {
  57. // the child object is now guaranteed to be a <MYTAG> element..
  58. doSomethingWithMYTAGElement (child);
  59. }
  60. @endcode
  61. @see forEachXmlChildElement
  62. */
  63. #define forEachXmlChildElementWithTagName(parentXmlElement, childElementVariableName, requiredTagName) \
  64. \
  65. for (juce::XmlElement* childElementVariableName = (parentXmlElement).getChildByName (requiredTagName); \
  66. childElementVariableName != nullptr; \
  67. childElementVariableName = childElementVariableName->getNextElementWithTagName (requiredTagName))
  68. //==============================================================================
  69. /** Used to build a tree of elements representing an XML document.
  70. An XML document can be parsed into a tree of XmlElements, each of which
  71. represents an XML tag structure, and which may itself contain other
  72. nested elements.
  73. An XmlElement can also be converted back into a text document, and has
  74. lots of useful methods for manipulating its attributes and sub-elements,
  75. so XmlElements can actually be used as a handy general-purpose data
  76. structure.
  77. Here's an example of parsing some elements: @code
  78. // check we're looking at the right kind of document..
  79. if (myElement->hasTagName ("ANIMALS"))
  80. {
  81. // now we'll iterate its sub-elements looking for 'giraffe' elements..
  82. forEachXmlChildElement (*myElement, e)
  83. {
  84. if (e->hasTagName ("GIRAFFE"))
  85. {
  86. // found a giraffe, so use some of its attributes..
  87. String giraffeName = e->getStringAttribute ("name");
  88. int giraffeAge = e->getIntAttribute ("age");
  89. bool isFriendly = e->getBoolAttribute ("friendly");
  90. }
  91. }
  92. }
  93. @endcode
  94. And here's an example of how to create an XML document from scratch: @code
  95. // create an outer node called "ANIMALS"
  96. XmlElement animalsList ("ANIMALS");
  97. for (int i = 0; i < numAnimals; ++i)
  98. {
  99. // create an inner element..
  100. XmlElement* giraffe = new XmlElement ("GIRAFFE");
  101. giraffe->setAttribute ("name", "nigel");
  102. giraffe->setAttribute ("age", 10);
  103. giraffe->setAttribute ("friendly", true);
  104. // ..and add our new element to the parent node
  105. animalsList.addChildElement (giraffe);
  106. }
  107. // now we can turn the whole thing into a text document..
  108. String myXmlDoc = animalsList.createDocument (String::empty);
  109. @endcode
  110. @see XmlDocument
  111. */
  112. class JUCE_API XmlElement
  113. {
  114. public:
  115. //==============================================================================
  116. /** Creates an XmlElement with this tag name. */
  117. explicit XmlElement (const String& tagName) noexcept;
  118. /** Creates a (deep) copy of another element. */
  119. XmlElement (const XmlElement& other);
  120. /** Creates a (deep) copy of another element. */
  121. XmlElement& operator= (const XmlElement& other);
  122. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  123. XmlElement (XmlElement&& other) noexcept;
  124. XmlElement& operator= (XmlElement&& other) noexcept;
  125. #endif
  126. /** Deleting an XmlElement will also delete all its child elements. */
  127. ~XmlElement() noexcept;
  128. //==============================================================================
  129. /** Compares two XmlElements to see if they contain the same text and attiributes.
  130. The elements are only considered equivalent if they contain the same attiributes
  131. with the same values, and have the same sub-nodes.
  132. @param other the other element to compare to
  133. @param ignoreOrderOfAttributes if true, this means that two elements with the
  134. same attributes in a different order will be
  135. considered the same; if false, the attributes must
  136. be in the same order as well
  137. */
  138. bool isEquivalentTo (const XmlElement* other,
  139. bool ignoreOrderOfAttributes) const noexcept;
  140. //==============================================================================
  141. /** Returns an XML text document that represents this element.
  142. The string returned can be parsed to recreate the same XmlElement that
  143. was used to create it.
  144. @param dtdToUse the DTD to add to the document
  145. @param allOnOneLine if true, this means that the document will not contain any
  146. linefeeds, so it'll be smaller but not very easy to read.
  147. @param includeXmlHeader whether to add the "<?xml version..etc" line at the start of the
  148. document
  149. @param encodingType the character encoding format string to put into the xml
  150. header
  151. @param lineWrapLength the line length that will be used before items get placed on
  152. a new line. This isn't an absolute maximum length, it just
  153. determines how lists of attributes get broken up
  154. @see writeToStream, writeToFile
  155. */
  156. String createDocument (const String& dtdToUse,
  157. bool allOnOneLine = false,
  158. bool includeXmlHeader = true,
  159. const String& encodingType = "UTF-8",
  160. int lineWrapLength = 60) const;
  161. /** Writes the document to a stream as UTF-8.
  162. @param output the stream to write to
  163. @param dtdToUse the DTD to add to the document
  164. @param allOnOneLine if true, this means that the document will not contain any
  165. linefeeds, so it'll be smaller but not very easy to read.
  166. @param includeXmlHeader whether to add the "<?xml version..etc" line at the start of the
  167. document
  168. @param encodingType the character encoding format string to put into the xml
  169. header
  170. @param lineWrapLength the line length that will be used before items get placed on
  171. a new line. This isn't an absolute maximum length, it just
  172. determines how lists of attributes get broken up
  173. @see writeToFile, createDocument
  174. */
  175. void writeToStream (OutputStream& output,
  176. const String& dtdToUse,
  177. bool allOnOneLine = false,
  178. bool includeXmlHeader = true,
  179. const String& encodingType = "UTF-8",
  180. int lineWrapLength = 60) const;
  181. /** Writes the element to a file as an XML document.
  182. To improve safety in case something goes wrong while writing the file, this
  183. will actually write the document to a new temporary file in the same
  184. directory as the destination file, and if this succeeds, it will rename this
  185. new file as the destination file (overwriting any existing file that was there).
  186. @param destinationFile the file to write to. If this already exists, it will be
  187. overwritten.
  188. @param dtdToUse the DTD to add to the document
  189. @param encodingType the character encoding format string to put into the xml
  190. header
  191. @param lineWrapLength the line length that will be used before items get placed on
  192. a new line. This isn't an absolute maximum length, it just
  193. determines how lists of attributes get broken up
  194. @returns true if the file is written successfully; false if something goes wrong
  195. in the process
  196. @see createDocument
  197. */
  198. bool writeToFile (const File& destinationFile,
  199. const String& dtdToUse,
  200. const String& encodingType = "UTF-8",
  201. int lineWrapLength = 60) const;
  202. //==============================================================================
  203. /** Returns this element's tag type name.
  204. E.g. for an element such as \<MOOSE legs="4" antlers="2">, this would return "MOOSE".
  205. @see hasTagName
  206. */
  207. inline const String& getTagName() const noexcept { return tagName; }
  208. /** Returns the namespace portion of the tag-name, or an empty string if none is specified. */
  209. String getNamespace() const;
  210. /** Returns the part of the tag-name that follows any namespace declaration. */
  211. String getTagNameWithoutNamespace() const;
  212. /** Tests whether this element has a particular tag name.
  213. @param possibleTagName the tag name you're comparing it with
  214. @see getTagName
  215. */
  216. bool hasTagName (const String& possibleTagName) const noexcept;
  217. /** Tests whether this element has a particular tag name, ignoring any XML namespace prefix.
  218. So a test for e.g. "xyz" will return true for "xyz" and also "foo:xyz", "bar::xyz", etc.
  219. @see getTagName
  220. */
  221. bool hasTagNameIgnoringNamespace (const String& possibleTagName) const;
  222. //==============================================================================
  223. /** Returns the number of XML attributes this element contains.
  224. E.g. for an element such as \<MOOSE legs="4" antlers="2">, this would
  225. return 2.
  226. */
  227. int getNumAttributes() const noexcept;
  228. /** Returns the name of one of the elements attributes.
  229. E.g. for an element such as \<MOOSE legs="4" antlers="2">, then
  230. getAttributeName(1) would return "antlers".
  231. @see getAttributeValue, getStringAttribute
  232. */
  233. const String& getAttributeName (int attributeIndex) const noexcept;
  234. /** Returns the value of one of the elements attributes.
  235. E.g. for an element such as \<MOOSE legs="4" antlers="2">, then
  236. getAttributeName(1) would return "2".
  237. @see getAttributeName, getStringAttribute
  238. */
  239. const String& getAttributeValue (int attributeIndex) const noexcept;
  240. //==============================================================================
  241. // Attribute-handling methods..
  242. /** Checks whether the element contains an attribute with a certain name. */
  243. bool hasAttribute (const String& attributeName) const noexcept;
  244. /** Returns the value of a named attribute.
  245. @param attributeName the name of the attribute to look up
  246. */
  247. const String& getStringAttribute (const String& attributeName) const noexcept;
  248. /** Returns the value of a named attribute.
  249. @param attributeName the name of the attribute to look up
  250. @param defaultReturnValue a value to return if the element doesn't have an attribute
  251. with this name
  252. */
  253. String getStringAttribute (const String& attributeName,
  254. const String& defaultReturnValue) const;
  255. /** Compares the value of a named attribute with a value passed-in.
  256. @param attributeName the name of the attribute to look up
  257. @param stringToCompareAgainst the value to compare it with
  258. @param ignoreCase whether the comparison should be case-insensitive
  259. @returns true if the value of the attribute is the same as the string passed-in;
  260. false if it's different (or if no such attribute exists)
  261. */
  262. bool compareAttribute (const String& attributeName,
  263. const String& stringToCompareAgainst,
  264. bool ignoreCase = false) const noexcept;
  265. /** Returns the value of a named attribute as an integer.
  266. This will try to find the attribute and convert it to an integer (using
  267. the String::getIntValue() method).
  268. @param attributeName the name of the attribute to look up
  269. @param defaultReturnValue a value to return if the element doesn't have an attribute
  270. with this name
  271. @see setAttribute
  272. */
  273. int getIntAttribute (const String& attributeName,
  274. int defaultReturnValue = 0) const;
  275. /** Returns the value of a named attribute as floating-point.
  276. This will try to find the attribute and convert it to an integer (using
  277. the String::getDoubleValue() method).
  278. @param attributeName the name of the attribute to look up
  279. @param defaultReturnValue a value to return if the element doesn't have an attribute
  280. with this name
  281. @see setAttribute
  282. */
  283. double getDoubleAttribute (const String& attributeName,
  284. double defaultReturnValue = 0.0) const;
  285. /** Returns the value of a named attribute as a boolean.
  286. This will try to find the attribute and interpret it as a boolean. To do this,
  287. it'll return true if the value is "1", "true", "y", etc, or false for other
  288. values.
  289. @param attributeName the name of the attribute to look up
  290. @param defaultReturnValue a value to return if the element doesn't have an attribute
  291. with this name
  292. */
  293. bool getBoolAttribute (const String& attributeName,
  294. bool defaultReturnValue = false) const;
  295. /** Adds a named attribute to the element.
  296. If the element already contains an attribute with this name, it's value will
  297. be updated to the new value. If there's no such attribute yet, a new one will
  298. be added.
  299. Note that there are other setAttribute() methods that take integers,
  300. doubles, etc. to make it easy to store numbers.
  301. @param attributeName the name of the attribute to set
  302. @param newValue the value to set it to
  303. @see removeAttribute
  304. */
  305. void setAttribute (const String& attributeName,
  306. const String& newValue);
  307. /** Adds a named attribute to the element, setting it to an integer value.
  308. If the element already contains an attribute with this name, it's value will
  309. be updated to the new value. If there's no such attribute yet, a new one will
  310. be added.
  311. Note that there are other setAttribute() methods that take integers,
  312. doubles, etc. to make it easy to store numbers.
  313. @param attributeName the name of the attribute to set
  314. @param newValue the value to set it to
  315. */
  316. void setAttribute (const String& attributeName,
  317. int newValue);
  318. /** Adds a named attribute to the element, setting it to a floating-point value.
  319. If the element already contains an attribute with this name, it's value will
  320. be updated to the new value. If there's no such attribute yet, a new one will
  321. be added.
  322. Note that there are other setAttribute() methods that take integers,
  323. doubles, etc. to make it easy to store numbers.
  324. @param attributeName the name of the attribute to set
  325. @param newValue the value to set it to
  326. */
  327. void setAttribute (const String& attributeName,
  328. double newValue);
  329. /** Removes a named attribute from the element.
  330. @param attributeName the name of the attribute to remove
  331. @see removeAllAttributes
  332. */
  333. void removeAttribute (const String& attributeName) noexcept;
  334. /** Removes all attributes from this element.
  335. */
  336. void removeAllAttributes() noexcept;
  337. //==============================================================================
  338. // Child element methods..
  339. /** Returns the first of this element's sub-elements.
  340. see getNextElement() for an example of how to iterate the sub-elements.
  341. @see forEachXmlChildElement
  342. */
  343. XmlElement* getFirstChildElement() const noexcept { return firstChildElement; }
  344. /** Returns the next of this element's siblings.
  345. This can be used for iterating an element's sub-elements, e.g.
  346. @code
  347. XmlElement* child = myXmlDocument->getFirstChildElement();
  348. while (child != nullptr)
  349. {
  350. ...do stuff with this child..
  351. child = child->getNextElement();
  352. }
  353. @endcode
  354. Note that when iterating the child elements, some of them might be
  355. text elements as well as XML tags - use isTextElement() to work this
  356. out.
  357. Also, it's much easier and neater to use this method indirectly via the
  358. forEachXmlChildElement macro.
  359. @returns the sibling element that follows this one, or zero if this is the last
  360. element in its parent
  361. @see getNextElement, isTextElement, forEachXmlChildElement
  362. */
  363. inline XmlElement* getNextElement() const noexcept { return nextListItem; }
  364. /** Returns the next of this element's siblings which has the specified tag
  365. name.
  366. This is like getNextElement(), but will scan through the list until it
  367. finds an element with the given tag name.
  368. @see getNextElement, forEachXmlChildElementWithTagName
  369. */
  370. XmlElement* getNextElementWithTagName (const String& requiredTagName) const;
  371. /** Returns the number of sub-elements in this element.
  372. @see getChildElement
  373. */
  374. int getNumChildElements() const noexcept;
  375. /** Returns the sub-element at a certain index.
  376. It's not very efficient to iterate the sub-elements by index - see
  377. getNextElement() for an example of how best to iterate.
  378. @returns the n'th child of this element, or nullptr if the index is out-of-range
  379. @see getNextElement, isTextElement, getChildByName
  380. */
  381. XmlElement* getChildElement (int index) const noexcept;
  382. /** Returns the first sub-element with a given tag-name.
  383. @param tagNameToLookFor the tag name of the element you want to find
  384. @returns the first element with this tag name, or nullptr if none is found
  385. @see getNextElement, isTextElement, getChildElement
  386. */
  387. XmlElement* getChildByName (const String& tagNameToLookFor) const noexcept;
  388. //==============================================================================
  389. /** Appends an element to this element's list of children.
  390. Child elements are deleted automatically when their parent is deleted, so
  391. make sure the object that you pass in will not be deleted by anything else,
  392. and make sure it's not already the child of another element.
  393. @see getFirstChildElement, getNextElement, getNumChildElements,
  394. getChildElement, removeChildElement
  395. */
  396. void addChildElement (XmlElement* newChildElement) noexcept;
  397. /** Inserts an element into this element's list of children.
  398. Child elements are deleted automatically when their parent is deleted, so
  399. make sure the object that you pass in will not be deleted by anything else,
  400. and make sure it's not already the child of another element.
  401. @param newChildNode the element to add
  402. @param indexToInsertAt the index at which to insert the new element - if this is
  403. below zero, it will be added to the end of the list
  404. @see addChildElement, insertChildElement
  405. */
  406. void insertChildElement (XmlElement* newChildNode,
  407. int indexToInsertAt) noexcept;
  408. /** Creates a new element with the given name and returns it, after adding it
  409. as a child element.
  410. This is a handy method that means that instead of writing this:
  411. @code
  412. XmlElement* newElement = new XmlElement ("foobar");
  413. myParentElement->addChildElement (newElement);
  414. @endcode
  415. ..you could just write this:
  416. @code
  417. XmlElement* newElement = myParentElement->createNewChildElement ("foobar");
  418. @endcode
  419. */
  420. XmlElement* createNewChildElement (const String& tagName);
  421. /** Replaces one of this element's children with another node.
  422. If the current element passed-in isn't actually a child of this element,
  423. this will return false and the new one won't be added. Otherwise, the
  424. existing element will be deleted, replaced with the new one, and it
  425. will return true.
  426. */
  427. bool replaceChildElement (XmlElement* currentChildElement,
  428. XmlElement* newChildNode) noexcept;
  429. /** Removes a child element.
  430. @param childToRemove the child to look for and remove
  431. @param shouldDeleteTheChild if true, the child will be deleted, if false it'll
  432. just remove it
  433. */
  434. void removeChildElement (XmlElement* childToRemove,
  435. bool shouldDeleteTheChild) noexcept;
  436. /** Deletes all the child elements in the element.
  437. @see removeChildElement, deleteAllChildElementsWithTagName
  438. */
  439. void deleteAllChildElements() noexcept;
  440. /** Deletes all the child elements with a given tag name.
  441. @see removeChildElement
  442. */
  443. void deleteAllChildElementsWithTagName (const String& tagName) noexcept;
  444. /** Returns true if the given element is a child of this one. */
  445. bool containsChildElement (const XmlElement* possibleChild) const noexcept;
  446. /** Recursively searches all sub-elements to find one that contains the specified
  447. child element.
  448. */
  449. XmlElement* findParentElementOf (const XmlElement* elementToLookFor) noexcept;
  450. //==============================================================================
  451. /** Sorts the child elements using a comparator.
  452. This will use a comparator object to sort the elements into order. The object
  453. passed must have a method of the form:
  454. @code
  455. int compareElements (const XmlElement* first, const XmlElement* second);
  456. @endcode
  457. ..and this method must return:
  458. - a value of < 0 if the first comes before the second
  459. - a value of 0 if the two objects are equivalent
  460. - a value of > 0 if the second comes before the first
  461. To improve performance, the compareElements() method can be declared as static or const.
  462. @param comparator the comparator to use for comparing elements.
  463. @param retainOrderOfEquivalentItems if this is true, then items which the comparator
  464. says are equivalent will be kept in the order in which they
  465. currently appear in the array. This is slower to perform, but
  466. may be important in some cases. If it's false, a faster algorithm
  467. is used, but equivalent elements may be rearranged.
  468. */
  469. template <class ElementComparator>
  470. void sortChildElements (ElementComparator& comparator,
  471. bool retainOrderOfEquivalentItems = false)
  472. {
  473. const int num = getNumChildElements();
  474. if (num > 1)
  475. {
  476. HeapBlock <XmlElement*> elems ((size_t) num);
  477. getChildElementsAsArray (elems);
  478. sortArray (comparator, (XmlElement**) elems, 0, num - 1, retainOrderOfEquivalentItems);
  479. reorderChildElements (elems, num);
  480. }
  481. }
  482. //==============================================================================
  483. /** Returns true if this element is a section of text.
  484. Elements can either be an XML tag element or a secton of text, so this
  485. is used to find out what kind of element this one is.
  486. @see getAllText, addTextElement, deleteAllTextElements
  487. */
  488. bool isTextElement() const noexcept;
  489. /** Returns the text for a text element.
  490. Note that if you have an element like this:
  491. @code<xyz>hello</xyz>@endcode
  492. then calling getText on the "xyz" element won't return "hello", because that is
  493. actually stored in a special text sub-element inside the xyz element. To get the
  494. "hello" string, you could either call getText on the (unnamed) sub-element, or
  495. use getAllSubText() to do this automatically.
  496. Note that leading and trailing whitespace will be included in the string - to remove
  497. if, just call String::trim() on the result.
  498. @see isTextElement, getAllSubText, getChildElementAllSubText
  499. */
  500. const String& getText() const noexcept;
  501. /** Sets the text in a text element.
  502. Note that this is only a valid call if this element is a text element. If it's
  503. not, then no action will be performed. If you're trying to add text inside a normal
  504. element, you probably want to use addTextElement() instead.
  505. */
  506. void setText (const String& newText);
  507. /** Returns all the text from this element's child nodes.
  508. This iterates all the child elements and when it finds text elements,
  509. it concatenates their text into a big string which it returns.
  510. E.g. @code<xyz>hello <x>there</x> world</xyz>@endcode
  511. if you called getAllSubText on the "xyz" element, it'd return "hello there world".
  512. Note that leading and trailing whitespace will be included in the string - to remove
  513. if, just call String::trim() on the result.
  514. @see isTextElement, getChildElementAllSubText, getText, addTextElement
  515. */
  516. String getAllSubText() const;
  517. /** Returns all the sub-text of a named child element.
  518. If there is a child element with the given tag name, this will return
  519. all of its sub-text (by calling getAllSubText() on it). If there is
  520. no such child element, this will return the default string passed-in.
  521. @see getAllSubText
  522. */
  523. String getChildElementAllSubText (const String& childTagName,
  524. const String& defaultReturnValue) const;
  525. /** Appends a section of text to this element.
  526. @see isTextElement, getText, getAllSubText
  527. */
  528. void addTextElement (const String& text);
  529. /** Removes all the text elements from this element.
  530. @see isTextElement, getText, getAllSubText, addTextElement
  531. */
  532. void deleteAllTextElements() noexcept;
  533. /** Creates a text element that can be added to a parent element.
  534. */
  535. static XmlElement* createTextElement (const String& text);
  536. //==============================================================================
  537. private:
  538. struct XmlAttributeNode
  539. {
  540. XmlAttributeNode (const XmlAttributeNode&) noexcept;
  541. XmlAttributeNode (const String& name, const String& value) noexcept;
  542. LinkedListPointer<XmlAttributeNode> nextListItem;
  543. String name, value;
  544. bool hasName (const String&) const noexcept;
  545. private:
  546. XmlAttributeNode& operator= (const XmlAttributeNode&);
  547. };
  548. friend class XmlDocument;
  549. friend class LinkedListPointer <XmlAttributeNode>;
  550. friend class LinkedListPointer <XmlElement>;
  551. friend class LinkedListPointer <XmlElement>::Appender;
  552. LinkedListPointer <XmlElement> nextListItem;
  553. LinkedListPointer <XmlElement> firstChildElement;
  554. LinkedListPointer <XmlAttributeNode> attributes;
  555. String tagName;
  556. XmlElement (int) noexcept;
  557. void copyChildrenAndAttributesFrom (const XmlElement&);
  558. void writeElementAsText (OutputStream&, int indentationLevel, int lineWrapLength) const;
  559. void getChildElementsAsArray (XmlElement**) const noexcept;
  560. void reorderChildElements (XmlElement**, int) noexcept;
  561. JUCE_LEAK_DETECTOR (XmlElement)
  562. };
  563. #endif // __JUCE_XMLELEMENT_JUCEHEADER__