Question about creating XML

I’m currently trying to learn about XML structures.
Taking an example from the JUCE demo code:

        <COLUMN columnId="2" name="Artist" width="150"/>

would this be the correct code to produce this (when converted back into a text document):

XmlElement DEMO_TABLE_DATA; // outter node  

XmlElement* columns = new XmlElement("COLUMNS");  

XmlElement* column = new XmlElement("COLUMN");  
column->setAttribute("columnId", 2);
column->setAttribute("name", "Artist");
column->setAttribute("width", 150);  


fixed variable names crept in from my actual code

No, that’s all a bit muddled, you’re not adding things to parents correctly.

Might be easier to understand if you use createNewChildElement() - you can find plenty of examples of that in the codebase if you search.

And it’s a lot quicker to print it out with createDocument() to see for yourself whether it works than to ask us whether it works!

1 Like