Skip to main content
Administrator Guide
Last Updated: 2023-06-23
Convert Text to XML with a Text Schema File

Convert Text to XML with a Text Schema File

Create an assembly containing a
textschema
step. Obtain the sample text that will form the basis of your text schema.
The
textschema
step enables you to convert text to XML using a text schema. To develop a text schema, you must know the structure of the data that you want to transform. The process is considerably simplified by having a small sample document containing representative data. This topic assumes that you have such a sample.
You can use the
textschema
step to convert XML to text or to transform delimited files, but in most cases it's simpler to use the
XTT
step and the
csv-to-xml
step, respectively.
  1. In the
    textschema
    step's
    Properties
    view, click
    Create Text Schema File
    .
  2. Select a parent folder for the text schema file and provide a filename. If required, specify the target namespace URI.
  3. Studio opens the Text Schema Editor and displays the new text schema in its
    Tree
    view.
  4. Cut and paste your sample text into the area in the upper right of the Text Schema Editor, replacing
    initial-text
    .
    To strip the terminating linefeed from input files, add this attribute to the root schema element:
    ts:eofStrip="
"
    .
  5. Begin describing the sample text. Select the first field, then right-click it and select
    Create Field
    .
    If you don't have a sample of the text you want to convert but know its structure, you can edit the text schema's
    Source
    view directly.
  6. On the
    Identity
    page of the
    Create Field Wizard
    , provide a basic description of the field. As you complete the task, consider:
    Option Description
    Name
    A name for the field.
    Occurrence
    The options are:
    • Default
      : The field is mandatory and occurs only once.
    • Required
      : Same as default.
    • Optional
      : The field is optional can occur only once.
    • Multiple Optional
      : The field is optional and can occur multiple times.
    • Multiple Required
      : The field is mandatory and can occur multiple times.
    Start Tag
    A regular expression that specifies the text that causes an element to be generated. Note that the text matching this expression doesn't form part of the output value. If you want the matched text to display in the output value, use the
    ts:format
    option.
    End Tag
    A regular expression that specifies the text that marks the end of an element. Note that the text matching this expression doesn't form part of the output value. If you want the matched text to display in the output value, use the
    ts:format
    option.
    Truncate
    Specifies whether to truncate overflowing data in a fixed-length field or throw an error. The default value is
    true
    .
    Separator
    A regular expression that specifies a character that separates repeated fields. Enabled only if you select the
    Multiple Optional
    or
    Multiple Required
    occurrence options.
    Omit
    Specifies whether to omit the field from the output in a
    text-to-XML
    or
    XML-to-text
    transformation. The default is no omission.
  7. On the
    Delimit
    page of the
    Create Field Wizard
    , describe how many characters from the sample text represent a field:
    Option Description
    Format
    A regular expression that identifies valid patterns of text for a field. Use this expression as an alternative to
    Start Tag
    and
    End Tag
    to ensure that all of the matched text displays in the output. You can also use it when dealing with multiply occurring values so it's clear when the end of the sequence occurs.
    Fixed Length
    Specifies the length of fixed-length fields. Includes quotation marks and escape characters.
    Quoted
    Indicates whether string values are treated as quoted strings. The options are:
    • Default
      :
    • always
      :
    • always-including-empty
      :
    • optional
      :
    • never
      :
    Padding
    A regular expression that identifies any padding text within fixed-length fields.
    Preferred Padding
    Specifies the value to be used if the
    Padding
    expression can match more than 1 possible string.
    Align
    Specifies the alignment of fixed-length fields that require padding.
  8. On the
    Interpret
    page of the
    Create Field Wizard
    , describe how many characters from the sample text represent a field:
    Option Description
    Type
    The field's data type.
    Default Value
    A default value for the field.
    Date Format
    Specifies a pattern for dates or datetimes. Supports any pattern allowed by Java's
    SimpleDateFormat
    .
    Date Language
    Specifies the date language to use when interpreting dates. Ensures that the name is handled in the appropriate language when the date format uses the names of months. The default value is
    EN
    .
    Two Digit Year
    Specifies a value for interpreting 2-digit year dates. The text schema parser interprets 2-digit year dates that occur before that value as occurring in the current century. Example: if you enter
    18
    , the parser interprets
    14
    as
    2014
    and
    96
    as
    1996
    .
    Number Format
    Specifies a pattern for numbers. Supports any pattern allowed by Java's
    DecimalFormat
    .
    Decimal Separator
    Specifies the separator used for decimal numbers.
    Grouping Separator
    Specifies the thousands grouping separator for numbers.
  9. Repeat steps 6-9 for each field in the sample text, adding new elements in the
    Tree
    view. When you've created all of the required field definitions, delete the remaining
    Unparsed
    child element.
  10. To wrap all of the elements you've created into a complex type, select them, right-click them, and select
    Wrap Elements
    . Then provide a name and an occurrence value for the wrapper element.
  11. In the wrapper element's
    Properties
    view, select
    /n
    from the
    End Tag
    drop-down list.
  12. The default schema root element is named
    File
    . On the
    Schema
    tab of the element's
    Properties
    view, provide a more meaningful name.
  13. In the
    Properties
    view of the top level
    schema
    element, the
    Root Element
    property has the value
    tns:File
    . Replace
    File
    with the meaningful name you selected for the root element.
  14. To remove any extra spaces from the generated output, select the
    Properties
    view of the top level
    schema
    element. Select
    +
    from the
    Padding
    drop-down list. Save the schema.