Translations of this page:
 

Creating Questionnaires as XML Files (Guide for AI Assistants)

This page is meant for AI assistants (ChatGPT, Claude, Gemini, …) that create a file for SoSci Survey users, which the users then import into their survey project. The file contains questions (one section in the list of questions) and, optionally, a questionnaire that arranges these questions on pages.

Related pages:

Procedure

  1. Clarify the content with the user: questions, response options, scales, order, filters.
  2. Clarify the languages: In which language are the texts (base language)? Shall there be translations?
  3. Create the file according to the rules below and output it completely (one code block, file extension .xml).
  4. The user saves the file and imports it in SoSci Survey via List of Questions → New section → Import Questions or Other Content from an XML File. During the import, SoSci Survey asks for the ID of the new section and the name of the questionnaire. Existing contents of the project are kept.
  5. If the import reports errors or warnings, ask the user for the text of the messages and correct the file.

Complete Example

The example contains a section “LI” with a welcome text and three questions (selection, scale, open text input), English texts with a German translation, and a questionnaire with two pages and a filter.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE surveyContent SYSTEM "https://www.soscisurvey.de/templates/doctype.survey.dtd">
<surveyContent version="2.5">
<program>SoSci Survey</program>
<version>4.0.03</version>
<timestamp>2026-11-25 12:00:00</timestamp>
<title>Library Satisfaction</title>
<description>Short questionnaire on library use and satisfaction</description>
<language>eng</language>
<attributes.specific program="ofb">
<attr id="language">eng</attr>
<attr id="translations">ger</attr>
</attributes.specific>
<section>
<title>Library</title>
<attributes.specific program="ofb">
<attr id="id">LI</attr>
</attributes.specific>
<question>
<description>Welcome</description>
<class>TextContent</class>
<title />
<explanation />
<headerText>
<txt>Welcome</txt>
<txt lng="ger">Willkommen</txt>
</headerText>
<lead>
<txt><![CDATA[Thank you for taking part in our survey. It takes about 3 minutes.]]></txt>
<txt lng="ger"><![CDATA[Vielen Dank, dass Sie an unserer Befragung teilnehmen. Die Beantwortung dauert etwa 3 Minuten.]]></txt>
</lead>
<attributes.specific program="ofb">
<attr id="id">1</attr>
</attributes.specific>
</question>
<question>
<description>Frequency of use</description>
<class>select</class>
<title>
<txt>How often do you use the library?</txt>
<txt lng="ger">Wie oft nutzen Sie die Bibliothek?</txt>
</title>
<explanation />
<attributes.specific program="ofb">
<attr id="id">2</attr>
<attr id="restrictions.answered">yes</attr>
</attributes.specific>
<item>
<text>
<txt>several times a week</txt>
<txt lng="ger">mehrmals pro Woche</txt>
</text>
<attributes.specific program="ofb">
<attr id="id">1</attr>
</attributes.specific>
</item>
<item>
<text>
<txt>about once a week</txt>
<txt lng="ger">etwa einmal pro Woche</txt>
</text>
<attributes.specific program="ofb">
<attr id="id">2</attr>
</attributes.specific>
</item>
<item>
<text>
<txt>less often</txt>
<txt lng="ger">seltener</txt>
</text>
<attributes.specific program="ofb">
<attr id="id">3</attr>
</attributes.specific>
</item>
<item>
<text>
<txt>never</txt>
<txt lng="ger">nie</txt>
</text>
<attributes.specific program="ofb">
<attr id="id">4</attr>
</attributes.specific>
</item>
</question>
<question>
<description>Satisfaction</description>
<class>scale</class>
<title>
<txt>To what extent do you agree with the following statements?</txt>
<txt lng="ger">Inwieweit stimmen Sie den folgenden Aussagen zu?</txt>
</title>
<explanation />
<labels>
<li i="1">
<txt>strongly disagree</txt>
<txt lng="ger">stimme überhaupt nicht zu</txt>
</li>
<li i="5">
<txt>strongly agree</txt>
<txt lng="ger">stimme voll und ganz zu</txt>
</li>
</labels>
<residualOptions>
<li i="0">
<txt>don't know</txt>
<txt lng="ger">weiß nicht</txt>
</li>
</residualOptions>
<attributes.specific program="ofb">
<attr id="id">3</attr>
<attr id="scale.niveau">5</attr>
</attributes.specific>
<item>
<text>
<txt>I find the books I am looking for.</txt>
<txt lng="ger">Ich finde die Bücher, die ich suche.</txt>
</text>
<attributes.specific program="ofb">
<attr id="id">1</attr>
</attributes.specific>
</item>
<item>
<text>
<txt>The opening hours suit my daily life.</txt>
<txt lng="ger">Die Öffnungszeiten passen zu meinem Alltag.</txt>
</text>
<attributes.specific program="ofb">
<attr id="id">2</attr>
</attributes.specific>
</item>
<item>
<text>
<txt>It is often too noisy for me.</txt>
<txt lng="ger">Es ist mir oft zu laut.</txt>
</text>
<invert>yes</invert>
<attributes.specific program="ofb">
<attr id="id">3</attr>
</attributes.specific>
</item>
</question>
<question>
<description>Reasons for not using</description>
<class>text</class>
<title>
<txt>Why don't you use the library?</txt>
<txt lng="ger">Warum nutzen Sie die Bibliothek nicht?</txt>
</title>
<explanation />
<attributes.specific program="ofb">
<attr id="id">4</attr>
</attributes.specific>
<item>
<text />
<attributes.specific program="ofb">
<attr id="id">1</attr>
<attr id="height">120</attr>
</attributes.specific>
</item>
</question>
</section>
<questionnaire>
<title>Library Survey</title>
<attributes.specific program="ofb">
<attr id="id">library</attr>
<attr id="content">&lt;?xml version="1.0"?&gt;
&lt;questionnaire&gt;
 
&lt;page&gt;
&lt;question id="LI01" /&gt;
&lt;question id="LI02" /&gt;
&lt;/page&gt;
 
&lt;page&gt;
&lt;php&gt;&lt;![CDATA[
if (value('LI02') == 4) {
  question('LI04');
} else {
  question('LI03');
}
]]&gt;&lt;/php&gt;
&lt;/page&gt;
 
&lt;/questionnaire&gt;</attr>
</attributes.specific>
</questionnaire>
</surveyContent>

File Structure

  • The file starts with <?xml version="1.0" encoding="UTF-8" ?> and the <!DOCTYPE ...> line as in the example. The file must be UTF-8 encoded.
  • The root element <surveyContent version="2.5"> contains, in this order: <program>, <version>, <timestamp>, <title>, <description>, <language>, <attributes.specific> (languages), exactly one <section> and optionally exactly one <questionnaire>.
  • <title> and <description> describe the file. SoSci Survey suggests the name of the questionnaire based on the title during the import.
  • For several sections, create several files – or a project file (see below).

Languages

  • Languages are given as three-letter codes, e.g. eng (English), ger (German), fre (French), spa (Spanish), ita (Italian).
  • <language> and <attr id="language"> state the base language, <attr id="translations"> the translations (several separated by commas). Without translations, <attr id="translations"> is omitted.
  • A translatable text contains one <txt> without lng for the base language and one <txt lng="..."> per translation. Without translations, the text may also be written directly in the element: <title>How old are you?</title>.
  • During the import, the user can choose whether to apply the language settings. If not, texts in languages that the project does not use are not imported.

Section and IDs

  • The section (<section>) has a title and an ID of two capital letters (<attr id="id">LI</attr>). The user may choose another ID during the import; references in the questionnaire are then adjusted automatically.
  • Each question has a number from 1 to 99 (<attr id="id">). It makes up the question ID: section + two-digit number, e.g. LI02. This ID is used in the questionnaire and in PHP code.
  • Each item has a number (<attr id="id">), which also is the response code in selection questions. The variable of an item is named e.g. LI03_01 (question LI03, item 1). In selection questions (select, dropdown), the variable of the question (LI02) stores the code of the selected option.
  • The positions (<attr id="pos">) may be omitted; then the order in the file applies.

Questions

  • A <question> element always needs <description> (internal description, not visible to respondents), <class> (the question type), <title> (the question text) and <explanation> (instructions) – empty as <title /> or <explanation />.
  • The elements within <question> and <item> have a fixed order. The reference states this order, and which attributes are elements of their own and which are written as <attr id="..."> in <attributes.specific program="ofb">.
  • Only specify attributes that differ from the default value. Only use attributes and values that the reference lists for the respective question type; unknown attributes are ignored with a warning during the import.
  • Yes/no attributes have the values yes and no. Widths and heights are given in pixels. Only specify a height for a text input if the field shall have several lines (at least 32 pixels).
  • Label scales (scale, gradual, slider, polar) with <labels>: i is the scale value, e.g. i="1" for the minimum and i="5" for the maximum of a 5-point scale (<attr id="scale.niveau">5</attr>). A residual option (“don't know”) goes into <residualOptions> with i="0" and is stored with the code -1.
  • Texts for respondents may contain HTML. Enclose texts with <, & or HTML tags in <![CDATA[ ... ]]>.
  • Texts without a response (welcome text, notes, headings) are not questions but media elements of the type TextContent. In the file, they are nevertheless written as <question> in the section and get an ID like a question: the heading in <headerText>, the text in <lead>.

Questionnaire

  • <questionnaire> contains <title> and, in <attributes.specific>, the name (<attr id="id">, up to 40 characters: letters without umlauts, digits, - and _) and the content (<attr id="content">).
  • The content is an XML document itself, stored as text in the attribute. Write it as normal XML first, then escape it completely: & becomes &amp;, < becomes &lt;, > becomes &gt;. The content must start with <?xml version="1.0"?> (escaped: &lt;?xml version="1.0"?&gt;).
  • The questionnaire consists of <page> elements in the order of the pages. A page contains:
    • <question id="LI02" /> – a question from the list of questions
    • <php><![CDATA[ ... ]]></php> – PHP code, e.g. for filters (see below)
    • <html><![CDATA[ ... ]]></html> – HTML code that is placed directly on the page
  • The attributes intID (internal numbers) may be omitted; SoSci Survey adds them.
  • SoSci Survey adds the final page (end of the questionnaire) automatically, it is not specified.

Filters and PHP Code

  • Filters are implemented as PHP code on the page where the questions are displayed. value() reads responses from previous pages, e.g. value('LI02') for the code of the selected option. question('LI04') displays a question, goToPage() jumps to another page.
  • PHP code is only executed when the respondent clicks “Next” and the next page is created. So a filter cannot react to responses on the same page; that requires JavaScript.
  • The PHP code runs in a sandbox. Only the functions from the manual are allowed; echo, $_GET/$_POST, global variables as well as file and database access are not possible. Details: SoSci Survey PHP Sandbox Context.

Complete Project (Advanced)

A project file (root element <surveyProject>) contains a complete project: several sections, several questionnaires, text elements and settings. Only use it if the user explicitly wants a complete project, e.g. for a new, empty project.

  • When importing a project file, SoSci Survey asks whether the previous contents of the project are deleted. Point this out to the user.
  • Structure: <surveyProject version="2.5" progversion="4.0.03"> with <title>, <description>, <attributes.specific> (languages as above), followed by any number of <section> and <questionnaire> (order according to the DTD: section before questionnaire).
  • Each section has its own ID and a position (<attr id="pos">). The IDs are not adjusted, so references in the questionnaire must match the IDs in the file.

Checklist Before Output

  • Header, DOCTYPE and version="2.5" as in the example, file in UTF-8.
  • Each question has <description>, <class>, <title> and <explanation> in this order, the other elements in the order of the reference.
  • Question types and attributes are taken from the reference; values are allowed values.
  • Numbers of questions (1–99) and items are unique within their section or question.
  • Each ID used in the questionnaire (e.g. LI04) exists in the section.
  • The questionnaire content is completely escaped and starts with &lt;?xml version="1.0"?&gt;.
  • No HTML forms (<form>, <input>) in texts: such inputs are not stored. Use the question types for inputs.
en/ai-xml.txt · Last modified: by 127.0.0.1
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki