Create an XML structure

    <TABLE_DATA>
<HEADERS>
    <COLUMN columnId="1" name="ID" width="50"/>
    <COLUMN columnId="2" name="Module" width="200"/>
    <COLUMN columnId="3" name="Name" width="200"/>
    <COLUMN columnId="4" name="Version" width="100"/>
    <COLUMN columnId="5" name="License" width="100"/>
    <COLUMN columnId="6" name="Groups" width="50"/>
    <COLUMN columnId="7" name="Dependencies" width="50"/>
    <COLUMN columnId="8" name="Description" width="300"/>
    <COLUMN columnId="9" name="Select" width="50"/>
</HEADERS>
<DATA>
    <ITEM ID="01" Module="juce_analytics" Name="JUCE analytics classes" Version="5.2.0" License="GPL/Commercial" Groups="2" Dependencies="1" Description="Classes to collect analytics and send to destinations." Select="0"/>
    <ITEM ID="02" Module="juce_audio_basics" Name="JUCE audio and MIDI data classes" Version="5.2.0" License="ISC" Groups="7" Dependencies="1" Description="Classes for audio buffer manipulation, midi message handling, synthesis, etc." Select="0"/>
    <ITEM ID="03" Module="juce_audio_devices" Name="JUCE audio and MIDI I/O device classes" Version="5.2.0" License="ISC" Groups="3" Dependencies="2" Description="Classes to play and record from audio and MIDI I/O devices." Select="0"/>
    <ITEM ID="04" Module="juce_audio_formats" Name="JUCE audio file format codecs" Version="5.2.0" License="GPL/Commercial" Groups="3" Dependencies="1" Description="Classes for reading and writing various audio file formats." Select="0"/>
    <ITEM ID="05" Module="juce_audio_plugin_client" Name="JUCE audio plugin wrapper classes" Version="5.2.0" License="GPL/Commercial" Groups="7" Dependencies="3" Description="Classes for building VST, VST3, AudioUnit, AAX and RTAS plugins." Select="0"/>
    <ITEM ID="06" Module="juce_audio_processors" Name="JUCE audio processor classes" Version="5.2.0" License="GPL/Commercial" Groups="5" Dependencies="2" Description="Classes for loading and playing VST, AU, or internally-generated audio processors." Select="0"/>
    <ITEM ID="07" Module="juce_audio_utils" Name="JUCE extra audio utility classes" Version="5.2.0" License="GPL/Commercial" Groups="3" Dependencies="4" Description="Classes for audio-related GUI and miscellaneous tasks." Select="0"/>
    <ITEM ID="08" Module="juce_blocks_basics" Name="Provides low-level control over ROLI BLOCKS devices" Version="5.2.0" License="ISC" Groups="6" Dependencies="2" Description="JUCE wrapper for low-level control over ROLI BLOCKS devices." Select="0"/>
    <ITEM ID="09" Module="juce_box2d" Name="JUCE wrapper for the Box2D physics engine" Version="5.2.0" License="GPL/Commercial" Groups="2" Dependencies="1" Description="The Box2D physics engine and some utility classes." Select="0"/>
    <ITEM ID="10" Module="juce_core" Name="JUCE core classes" Version="5.2.0" License="ISC" Groups="16" Dependencies="0" Description="The essential set of basic JUCE classes, as required by all the other JUCE modules." Select="1"/>
    <ITEM ID="11" Module="juce_cryptography" Name="JUCE cryptography classes" Version="5.2.0" License="GPL/Commercial" Groups="2" Dependencies="1" Description="Classes for various basic cryptography functions, including RSA, Blowfish, MD5, SHA, etc." Select="0"/>
    <ITEM ID="12" Module="juce_data_structures" Name="JUCE data model helper classes" Version="5.2.0" License="GPL/Commercial" Groups="3" Dependencies="1" Description="Classes for undo/redo management, and smart data structures." Select="1"/>
    <ITEM ID="13" Module="juce_dsp" Name="JUCE DSP classes" Version="5.2.0" License="GPL/Commercial" Groups="5" Dependencies="3" Description="Classes for audio buffer manipulation, digital audio processing, filtering, oversampling, fast math functions etc." Select="0"/>
    <ITEM ID="14" Module="juce_events" Name="JUCE message and event handling classes" Version="5.2.0" License="ISC" Groups="4" Dependencies="1" Description="Classes for running an application's main event loop and sending/receiving messages, timers, etc." Select="1"/>
    <ITEM ID="15" Module="juce_graphics" Name="JUCE graphics classes" Version="5.2.0" License="GPL/Commercial" Groups="8" Dependencies="1" Description="Classes for 2D vector graphics, image loading/saving, font handling, etc." Select="1"/>
    <ITEM ID="16" Module="juce_gui_basics" Name="JUCE GUI core classes" Version="5.2.0" License="GPL/Commercial" Groups="16" Dependencies="3" Description="Basic user-interface components and related classes." Select="1"/>
    <ITEM ID="17" Module="juce_gui_extra" Name="JUCE extended GUI classes" Version="5.2.0" License="GPL/Commercial" Groups="4" Dependencies="1" Description="Miscellaneous GUI classes for specialised tasks." Select="0"/>
    <ITEM ID="18" Module="juce_opengl" Name="JUCE OpenGL classes" Version="5.2.0" License="GPL/Commercial" Groups="3" Dependencies="1" Description="Classes for rendering OpenGL in a JUCE window." Select="0"/>
    <ITEM ID="19" Module="juce_osc" Name="JUCE OSC classes" Version="5.2.0" License="GPL/Commercial" Groups="1" Dependencies="2" Description="Open Sound Control implementation." Select="0"/>
    <ITEM ID="20" Module="juce_product_unlocking" Name="JUCE Online marketplace support" Version="5.2.0" License="GPL/Commercial" Groups="2" Dependencies="2" Description="Classes for online product authentication." Select="0"/>
    <ITEM ID="21" Module="juce_video" Name="JUCE video playback and capture classes" Version="5.2.0" License="GPL/Commercial" Groups="2" Dependencies="2" Description="Classes for playing video and capturing camera input." Select="0"/>
</DATA></TABLE_DATA>

How can I create this XML structure?
I know how to add the “COLUMN” to <TABLE_DATA> but not, I make “COLUMN” as part of “HEADERS” and make “HEADERS” as part of <TABLE_DATA>.

How/where are you using XML in your code? Are you using juce::XmlElement or juce::ValueTree?

In general, you’ll want to create the HEADERS node first, add each of the COLUMN nodes, then add that HEADER node to the TABLE_DATA node.

1 Like

The main difference which one to choose is, if you need text nodes. That is content between an opening tag and a closing tag, like you know from html: <a href="foo">Some text</a>.
That feature is not available using ValueTree. In that case you need to use the juce::XmlElement and related classes.

The example you posted can be easily coded with juce::ValueTree and thanks to the initialisers even in one statement:

auto tree = juce::ValueTree ("TABLE_DATA", {},
    {"HEADERS", {},
        {"COLUMN", {{"columnId", "1"},
                    {"name", "ID"},
                    {"width", 50}}},
        {"COLUMN", {{"columnId", "2"},
                    {"name", "Module"},
                    {"width", 200}}},
// ...
},
    {"DATA", {},
        {"ITEM", {{"ID", 01},
                  {"Module", "juce_analytics"},
                  {"Name", "JUCE analytics classes"},
                  {"Version", "5.2.0"},
// ...
}};

Basically the juce::ValueTree takes three arguments: typename, properties as list of tuples and children again as initialiser list.

Didn’t count the closing brackets…

And using variables as identifiers/property names is strongly recommended, other than I did in the example

1 Like

Thanks.
I use juce::XmlElement and also know how to add ChildElements to an XmlElement.

But don’t know how I add the HEADER node to the TABLE_DATA node after adding colums to the HEADER node.

I will just try it with ValueTree.

If you understand the adding of child elements, you should have been able to sort out what you wanted… But we can help get you on the right path if you share some code - what have you tried?

Ok, I have now figured out myself what my mistake was.
Thanks for the help.

This is how it works now

// create an outer node called "PLUGIN_TABLE_TEMP_DATA"
juce::XmlElement pluginTableTempData("PLUGIN_TABLE_TEMP_DATA");

//juce::XmlElement pluginTableTempData_headers("HEADERS");
juce::XmlElement* pluginTableTempData_headers = new juce::XmlElement("HEADERS");

for (int i = 0; i < 10; ++i)
{
juce::XmlElement* pluginTableTempData_columnid = new juce::XmlElement("COLUMN");

// create the inner elements.
for (int j = 1; j < TableHeaderNammes.size() + 1; j++)
{
    pluginTableTempData_columnid->setAttribute("columnId", j);
    pluginTableTempData_columnid->setAttribute("width", "50");
}

// ..and add our new elements to the parent node
pluginTableTempData_headers->addChildElement(pluginTableTempData_columnid);
}

// add the parent node to the main node
pluginTableTempData.addChildElement(pluginTableTempData_headers);

Thanks for your help

Note that you could use createNewChildElement.