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.- In thetextschemastep'sPropertiesview, clickCreate Text Schema File.
- Select a parent folder for the text schema file and provide a filename. If required, specify the target namespace URI.
- Studio opens the Text Schema Editor and displays the new text schema in itsTreeview.
- Cut and paste your sample text into the area in the upper right of the Text Schema Editor, replacinginitial-text.To strip the terminating linefeed from input files, add this attribute to the root schema element:ts:eofStrip=" ".
- Begin describing the sample text. Select the first field, then right-click it and selectCreate 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'sSourceview directly.
- On theIdentitypage of theCreate Field Wizard, provide a basic description of the field. As you complete the task, consider:
Option Description NameA name for the field.OccurrenceThe 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 TagA 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 thets:formatoption.End TagA 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 thets:formatoption.TruncateSpecifies whether to truncate overflowing data in a fixed-length field or throw an error. The default value istrue.SeparatorA regular expression that specifies a character that separates repeated fields. Enabled only if you select theMultiple OptionalorMultiple Requiredoccurrence options.OmitSpecifies whether to omit the field from the output in atext-to-XMLorXML-to-texttransformation. The default is no omission. - On theDelimitpage of theCreate Field Wizard, describe how many characters from the sample text represent a field:
Option Description FormatA regular expression that identifies valid patterns of text for a field. Use this expression as an alternative toStart TagandEnd Tagto 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 LengthSpecifies the length of fixed-length fields. Includes quotation marks and escape characters.QuotedIndicates whether string values are treated as quoted strings. The options are:- Default:
- always:
- always-including-empty:
- optional:
- never:
PaddingA regular expression that identifies any padding text within fixed-length fields.Preferred PaddingSpecifies the value to be used if thePaddingexpression can match more than 1 possible string.AlignSpecifies the alignment of fixed-length fields that require padding. - On theInterpretpage of theCreate Field Wizard, describe how many characters from the sample text represent a field:
Option Description TypeThe field's data type.Default ValueA default value for the field.Date FormatSpecifies a pattern for dates or datetimes. Supports any pattern allowed by Java'sSimpleDateFormat.Date LanguageSpecifies 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 isEN.Two Digit YearSpecifies 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 enter18, the parser interprets14as2014and96as1996.Number FormatSpecifies a pattern for numbers. Supports any pattern allowed by Java'sDecimalFormat.Decimal SeparatorSpecifies the separator used for decimal numbers.Grouping SeparatorSpecifies the thousands grouping separator for numbers. - Repeat steps 6-9 for each field in the sample text, adding new elements in theTreeview. When you've created all of the required field definitions, delete the remainingUnparsedchild element.
- To wrap all of the elements you've created into a complex type, select them, right-click them, and selectWrap Elements. Then provide a name and an occurrence value for the wrapper element.
- In the wrapper element'sPropertiesview, select/nfrom theEnd Tagdrop-down list.
- The default schema root element is namedFile. On theSchematab of the element'sPropertiesview, provide a more meaningful name.
- In thePropertiesview of the top levelschemaelement, theRoot Elementproperty has the valuetns:File. ReplaceFilewith the meaningful name you selected for the root element.
- To remove any extra spaces from the generated output, select thePropertiesview of the top levelschemaelement. Select+from thePaddingdrop-down list. Save the schema.