XML question

I’m trying to use the xmldocument and xmlelement classes. I am getting a compile error on the following…

XmlDocument theDoc(File(sFilename));
XmlElement* mainElement = theDoc.getDocumentElement();  <---- C2228: left of '.getDocumentElement' must have class/struct/union

I’ve added …

class XMLDocument;

Is there some other header/class that I’m missing?

I’ve copied this directly from the xmldocument reference.


Do it like this:

Thanks Jules!

i know it’s 6 years later but i’m stuck on the same issue, i think this was the answer i was looking for but i can’t see it.

I’m not sure what the original answer was, but this will do it:

    XmlDocument xmlDoc (file);
    auto mainElement { xmlDoc.getDocumentElement () };

Best current practice would be simply

auto mainElement = juce::parseXML (file);

The XmlDocument class is still there but probably not necessary except for some more obscure use-cases.

1 Like