Skip to main content

Rigi Documentation

Configurable XML parser

Parser ID: txt-simple.

Key features:

  • Generic XML parser.

  • Configure XPath rules.

Description:

The possible number of XML file formats is endless. In Rigi, we basically want to process elements, each of which has a unique string ID, text, and an optional comment. The elements to be selected and the identifiers, texts, and comments can be specified using XPath expressions.

Examples:

The XPath expressions are best explained via examples:

Example 4. Identifiers as elements
XML1.png

Table 4.

Item

XPath expression

Description

Element

/Messages/Message

Select elements containing translatable texts.

String ID

./ID

The value of the ID element within the Element.

Text

./Description

The value of the Text element within the Element.

Comment

./Comment

The value of the Comment element within the Element.


xPaths-variable: /Messages/Message##./ID##./Description##./Comment


Example 5. Identifiers as attributes
XML2.png

xPaths-variable: /Messages/Message##@ID##./Description##./Comment


Parser settings:

  • Use Unix newlines (unixNewline).

    Default: false.

    If true, the parser will generate a Unix newline (\n). Otherwise, it will generate a Windows newline (\r\n).

  • XPaths (xPath) and Separator (xSeparator).

    You need to specify an xPath for each localizable text. An xPath definition consists of the following elements separated by a separator xSeparator:

    • An XPath expression to an element that contains an element or attribute with a localizable text.

    • An XPath expression to the string ID.

      Composed string ID

      You can compose a string ID by defining multiple expressions separated by a space. An expression can be an XPath expression or a hard-coded text surrounded by double quotes.

    • An XPath expression to the localizable text.

    • (Optional) An XPath expression to a comment.

    The default separator is ##, but it can be overridden using the xSeparator parser setting. 

    Example 6.

    If there were examples 1 and 2 in one file:

    XML3.png

    xPaths rules would be:

    /Messages/Message##./ID##./Description##./Comment

    /Messages/Message##@ID##./Description##./Comment


    Example 7. Composed string ID

    For the following example:

    XML_new_example.png

    xPath rules would be:

    /objects/object/text##../identifier "text"##.

    /objects/object/field/title##../../identifier "field" ../identifier "title"##../title

    Those rules will result in the following IDs and source texts:

    IDs

    Source texts

    Account.text

    Your account

    Account.field.Username.title

    Your username

    Address.text

    Your address

    Address.field.Street.title

    Streetname

    Address.field.Username.title

    Hello world


  • Use element name in key (fullKey).

    If set to true, include the name of the element as part of the key.

  • Skip source strings (regex) (skipSourceStrings).

    Each entry contains a regular expression. The parser will skip an entry in the XML file if the source string matches one of the entries.

  • Replacements (xReplacements).

    Each row starts with an XPath expression to the element, followed by a replacement variable to indicate how the locale must be written. The following replacement patterns are supported:

    • xxYY

      A language code consists of a language, a separator, and a locale. The parser supports the entry of the language and/or locale in lower or upper case. The separator can be -, _ or blank. Specify the combination with:

      • Language: xx or XX.

      • Separator: - or _ or blank.

      • Locale: yy or YY.

      Table 5. Examples for en-US

      Variable

      Result

      xx_yy

      en_us

      xx-yy

      en-us

      XX-YY

      EN-US

      xxYY

      enUS


      Example 8.
      XML_Replacement.png

      In this example, use the following expression to replace the locale ID:

      locale/@id xx_YY

      Use the following expression to replace xml:lang:

      locale/@xml:lang xx_YY


    • lang / country.

      If the replacement pattern contains the words lang or country (case insensitive), they will be replaced with the language and country name. The casing of the variables will define the casing of the language and country name.

      The following patterns are supported:

      • lang, Lang, LANG

      • country, Country, COUNTRY

      Table 6. Examples for nl-BE

      Variable

      Result

      lang (country)

      dutch (belgium)

      Lang (Country)

      Dutch (Belgium)

      LANG (COUNTRY)

      DUTCH (BELGIUM)

      ABCLangDEFCountryGHI

      ABCDutchDEFBelgiumGHI


      Example 9.

      In this example, we used the following expression to replace the locale ID:

      /Messages/@lang LANG (country)

      Result:

      XML_replace_example2.png


  • Skip elements on attribute (skipAttributes).

    Each line specifies an XPath to an attribute name and value. Elements that have an attribute with the specified value will be skipped.

    Example: /resources/string/@translatable false.

For other parser settings, see the Generic parser settings article.