XmlElement GetText Only From Current Element


I’m working on trying to convert an XML file which isn’t based on attributes (but on text nodes) into one which is attribute based to later use with ValueTrees.
Using getAllSubText() as suggested here gets the text for all of the child elements as well as the text from the element I need. Is there a function I can use to only get the text from the current element?


From the docs for getText():

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.

So probably something like this:

if (auto* node = xml->getFirstChildElement()) {
    text = node->getText();
    // ...



Ahh, I was using Xcode’s autocomplete to quickly scan the documents and missed that. I should really RTFM! Thanks again Daniel


No worries, glad I could help :slight_smile: