John
John

Reputation: 2852

XQuery and BaseX- How to store the output to a combobox?

I am using BaseX as backend to store XML Files. Front end is in Java. I want to populate certain elements data into a combobox. The output of the XQuery is string. I am facing problem to load this string in a combobox. Below is the XML file-

<Cities>
  <City><C>London</C></City>
  <City><C>New Delhi</C></City>
  <City><C>Mumbai</C></City>
  <City><C>Moscow</C></City>
  <City><C>Tokyo</C></City>
  <City><C>Mumbai</C></City>
  <City><C>Tokyo</C></City>
  <City><C>Mumbai</C></City>
  <City><C>Tokyo</C></City>
  <City><C>Mumbai</C></City>
  <City><C>New Delhi</C></City>
</Cities>

Using this XML file, I want to populate all the distinct cities in a combobox. This will be done by following XQuery-

for $x in distinct-values(doc("City")/Cities/City/C)
  return $x

The output of this is a simple string -

`London New Delhi Mumbai Moscow Tokyo`

There are 5 cities resulting from the query. How can I populate this in a combobox..?

Upvotes: 1

Views: 227

Answers (1)

Christian Gr&#252;n
Christian Gr&#252;n

Reputation: 6229

This might help:

element select {
  distinct-values(doc("City")/Cities/City/C) ! element option { . }
}

Upvotes: 3

Related Questions