Skip to main content

Rigi Documentation

XML parser with XPath
  • Parser ID: xml.

  • 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 14. Identifiers as elements
XML1.png

Table 12.

Item

XPath expression

Description

Element

/Messages/Message

Select elements with 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 15. Identifiers as attributes
XML2.png

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


Parser settings

  • XPath and separator.

    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 16.

    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 17. 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


  • fullKey

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

  • 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.

  • xReplacements

    Each row starts with an XPath expression to the element, followed by a replacement variable to indicate how the locale must be written. 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.

    Some examples for en-US:

    Table 13.

    Variable

    Result

    xx_yy

    en_us

    xx-yy

    en-us

    XX-YY

    EN-US

    xxYY

    enUS


    Example 18.
    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