Generate a Choice Master XML Using AI

In Questetra BPM Suite workflow Apps, you can upload a list of options as a Choice Master XML and share it across multiple dropdown menus or radio buttons. This is a convenient mechanism for centrally managing large lists, such as prefectures or postal codes, as well as lists that you want to reuse across multiple Apps.

Instructions on how to create a Choice Master XML are summarized in How to Create Choice Master XML (via text editors, Modeler, [Update Choice Master], external integrations, etc.). This article provides a detailed explanation of one of those methods: using AI (such as ChatGPT or Claude).

Tasks like creating correctly formatted XML from a mix of miscellaneous data or periodically converting official data into XML are areas where AI excels. In this article, we explain how to use AI for this purpose, broken down into two methods.

Table of Contents

A Choice Master XML has a simple structure where individual item elements for each choice are placed under the root element items. Each item has only two attributes: value (Choice ID) and display (Display Label).

<?xml version="1.0" encoding="UTF-8"?>
<items>
  <item value="1" display="Hokkaido" />
  <item value="2" display="Aomori Prefecture" />
</items>

Set the character encoding to UTF-8. For detailed attribute specifications, please refer to Choice XML Format (R3190).

When having AI generate content or verifying it afterward, the following points are particularly common stumbling blocks. Including these as conditions in the prompts you give the AI will help reduce the need for rework.

  • Explicitly specify XML escaping in the prompt. Special characters such as & < > " ' require entity reference escaping. AI usually understands this conversion, but when generating large outputs, it may occasionally miss some. Writing this condition in your prompt ensures reliability. If unescaped characters remain, an error will occur upon uploading: “Invalid XML file. Please check the XML format of the Choice Master.” (For format details, see R3190).
  • Make value unique. If the same ID is duplicated, only the first occurrence is loaded, and subsequent entries are ignored.
  • Do not include invisible characters. If invisible characters like tabs or extra leading/trailing whitespace get mixed into value, normalization (replacement with half-width spaces and trimming) will occur upon upload. As a result, values won’t match registered data, causing them to display as “(Deleted)”. Be careful, as these are easily introduced when copying and pasting from spreadsheet software.
  • Avoid half-width katakana. Although allowed in Unicode, depending on the display font or environment, characters may warp, or mixing full-width and half-width characters makes selection and searching difficult. It is best practice to standardize on full-width characters.
  • The maximum upload file size is 20 MB, and the maximum number of choices is 150,000. Choice IDs and Display Labels must each be within 1,000 characters. This accommodates large-scale masters that far exceed the limit for direct entry in Modeler (1,000 choices).

Where to register the created XML is a common topic regardless of how it was made. If sharing across multiple Apps, register it under System Settings > [App-shared Add-ons] (requires System Administrator privileges). If using within a single App, register it under the respective App’s [Add-ons] (requires App Administrator privileges). For details on proper usage, required permissions, and update procedures, refer to Creating a Choice Master XML with a Text Editor or the Modeler.

Suitable data: Small to medium-sized data unique to the organization, such as product codes, client names, department lists, or custom classification codes.

Paste rough data on hand—such as tables, bulleted lists, or CSV fragments—directly into the AI and have it convert the data into a finalized XML format. Since official public sources do not exist for organization-specific data, this route—where you pass the “actual values” to the AI and let it handle only the formatting—is ideal.

Prompt Template Example

Please convert the following data into a Questetra Choice Master XML.

Conditions:
- Root element is items; each line must follow the format <item value="..." display="..." />
- Include <?xml version="1.0" encoding="UTF-8"?> on the 1st line
- Always escape the 5 characters & < > " ' using entity references
- Make value unique
- Do not use half-width katakana
- Without adding unnecessary explanations, output the XML as an easily copyable code block (or a downloadable file if the volume is large)

Data:
1, Aobara Industry Co., Ltd.
2, Inaho Factory Co., Ltd.
3, Uranami System Co., Ltd.
4, Egarashi Techno Co., Ltd.

Expected Output:

<?xml version="1.0" encoding="UTF-8"?>
<items>
  <item value="1" display="Aobara Industry Co., Ltd." />
  <item value="2" display="Inaho Factory Co., Ltd." />
  <item value="3" display="Uranami System Co., Ltd." />
  <item value="4" display="Egarashi Techno Co., Ltd." />
</items>

Caution Regarding Completeness

When dealing with large volumes, AI may truncate output halfway through when outputting directly into the chat. If the dataset is sizable, having it output all items as a downloadable file from the start is the most reliable Approach. This prevents chat truncation and allows you to upload the file directly.

Additionally, have the AI count the items itself and perform a cross-check. After generation, ask the following:

How many <item> tags were output? How many items were in the input data?

It will count both and report whether anything is missing. If the counts do not match, rather than Appending missing items halfway through, have it regenerate a complete version containing all items.

There were [N] items in the input. Please identify the missing choices and re-output a complete version containing all [N] items as a file.

Suitable data: High-volume data, or officially distributed data that is updated regularly, such as postal codes, municipality codes, or local government codes.

If you have AI write XML directly as in Route A, large datasets are prone to premature truncation or hallucinations (generating incorrect values). Therefore, in this route, rather than writing the XML itself, you have the AI write a “conversion program” and receive the resulting XML alongside it.

The Approach is similar to Route A: pass the data you want to convert (CSV or ZIP files) to the AI. Then, simply ask it to provide both the conversion program and the resulting XML. The key point is not having the AI write items one by one, but leaving the processing itself to the program. Even with tens of thousands of items, none will be missed, and the program remains as a reusable, verifiable artifact in your hands.

Request Example

I want to convert Japan Post's postal code data (utf_ken_all.zip) into a Questetra Choice Master XML.
Please write a Python script and use it to perform the conversion.

- Root element is items; each choice must be in the format <item value="..." display="..." />
- Include <?xml version="1.0" encoding="UTF-8"?> on the 1st line
- Use the postal code for value, and address (Prefecture + City/Ward + Town area) for display
- Escape & < > " ' and ensure value is unique
- Output both the created script and the conversion result options.xml (in downloadable form)

Since the XML structure (items / item) is specific to Questetra, be sure to specify it. Otherwise, it may be output in a different format such as <options><option>. On the other hand, the AI can determine character encoding and delimiters of the provided file itself, so you don’t need to specify those details.

Output Example (Generated Script)

The script returned by the AI will look like the following:

import csv, io, zipfile

def esc(s):
    return (s.replace("&", "&").replace("<", "<").replace(">", ">")
            .replace('"', """).replace("'", "'"))

seen = set()
with zipfile.ZipFile("utf_ken_all.zip") as z:
    name = next(n for n in z.namelist() if n.upper().endswith(".CSV"))
    with z.open(name) as f, open("options.xml", "w", encoding="utf-8") as out:
        out.write('<?xml version="1.0" encoding="UTF-8"?>' + chr(10) + '<items>' + chr(10))
        for row in csv.reader(io.TextIOWrApper(f, encoding="utf-8-sig")):
            value = row[2]
            display = row[6] + row[7] + row[8]
            if value in seen:
                continue
            seen.add(value)
            out.write('  <item value="' + esc(value) + '" display="' + esc(display) + '" />' + chr(10))
        out.write('</items>' + chr(10))

print(len(seen), 'items output')

The key is letting the script side handle escaping, duplicate removal, and item count outputs. By outputting the item count at the end, you can perform cross-checking just like the “Caution Regarding Completeness” in Route A.

Taking It Further: Reusing the Script to Automate Updates

If you save the created script (for example, as convert.py), when data is updated, simply re-running it will produce the latest XML.

If you want to automate downloading as well, there are two Approaches. One is fetching outside the script. Download the latest ZIP using curl or similar tools, then process it with the script. Since fetching and conversion are separated, the steps are easy to understand, requiring only the execution of the following two lines during updates:

curl -O https://www.post.japanpost.jp/service/search/zipcode/download/utf/zip/utf_ken_all.zip
python3 convert.py

The second Approach is having the script itself download the file. Have the previous script improved as follows:

Please improve the script above so that it starts by downloading utf_ken_all.zip from Japan Post's official distribution page.
(Example: https://www.post.japanpost.jp/service/search/zipcode/download/utf/zip/utf_ken_all.zip
If the URL has changed, verify the latest URL on the official distribution page)
Complete fetching -> unzipping -> XML conversion in a single execution.

Doing this allows everything from fetching to conversion to complete in a single run, virtually automating update tasks. Since values are imported directly from the official source every time, hallucinations won’t creep in.

With either route, always upload the generated XML to verify operation. If an error occurs during upload, the majority of cases are caused by failure to properly escape characters.

When an error occurs, conveying the exact symptom to the AI for corrections is the fastest solution. For example, make a request like this:

When uploaded, it resulted in an error: "Invalid XML file. Please check the XML format of the Choice Master."
Please inspect whether unescaped special characters (& < > " ') remain, and return only the corrected XML.

Also, large files may not be supported in free trial environments. Please keep this in mind when testing large-scale choice masters.

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading