Getting the label field by the identifier of the value tag

We got a complex form (about 5000 lines XML with groups etc) and about 1700 records from that form on a recent installation of Aggregate. The form works as intended, the data is sound and I can read it to display the records on a map using Leaflet.

Unfortunately the good people, who have designed the form, have not documented it. As usual, many of the entries are multiple choice, where a section is called "electrical devices in household" and the labels for the list items read something like "Toaster" or "Washing Machine".
Of course the value stored to Aggregate would not be "Toaster" but a integer ID such as "3" and "5" for the washing machine. Thats fine and best practice, but we do not know, what the number means by looking at the data in Aggregate. There is a field named "ElectricalDevices" and the number.

We could look up the XML and do a lookup of labels (Toaster) to find what number is stored for that device if the field is ticked. Cumbersome, very cumbersome I'd say.

All we have to work with is the XML and I tried to read it with SimpleXML in PHP but it fails to import the file as readable Object (var_dump and print_r show it as empty, no error at importing whatsoever...)

Now I wonder how you usually deal with something like this. Is there any standard way to analyse and query the XML to find such information?

2. What app or server are you using and on what device and operating system? Include version numbers.
recent Aggregate on Linux /Tomcat
recent OKDCollect
3. What you have you tried to fix the problem?
Parsing the XML with SimpleXML/PHP
4. What steps can we take to reproduce the problem?
Try to find a label for a value, that is stored as an ID
5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
Unfortunately I am not authorized to post the actual XML file...

In the end I need lists of labels, the values seem to be integers always rising from 1.

So I did this:

sed -n '/select1 ref="/SURV/SOC/niveau_instruct/,/select/p' Base_line_Study.xml|egrep "label"|sed 's///g'|sed 's/</label>//g'|sed 's/^[ \t]*//' | sed 's/$/"/'|sed 's/^/"/'

This gives me a list like that:

"Secondaire général"
"Secondaire technique"
"Ecole professionnelle"

That can easily turned into an array, that I can use as a key to read the data.

1 Like