IPWorks EDI 2020 Python Edition

Questions / Feedback?

X12Reader Class

Properties   Methods   Events   Configuration Settings   Errors  

The X12Reader class is optimized for X12 documents, providing a simple way to parse X12 documents.

Syntax

class ipworksedi.X12Reader

Remarks

The class allows you to parse an incoming EDI document. This class works in two states, loading an entire document at once, or streaming portions of the document. These states are controlled by the BuildDOM property. By default BuildDOM is set to bdEntireDocument which parses the entire document at once, allowing you to use the x_path property to navigate the document.

To save memory for larger documents, you can choose to parse only sections of the document, instead of the entire document. When build_dom is set to per interchange (bdInterchange ) or per transaction (bdTransaction), the respective section of the document will be available for use with x_path from within the corresponding Start and End events. Finally, you may choose to set build_dom to bdNone, which means no DOM will be built and all data will be available only through events, but also will use very little memory. Below are example steps to parse an entire document:

  1. First, use load_schema to load a schema file into the class. (Only necessary when preserving document structure).
  2. Open an EDI document or stream by setting input via input_file or input_data and calling parse.
  3. If build_dom is set to bdEntireDocument, the events of the class will fire as the document is parsed, and x_path may be set to access any part of the document.

    If bdInterchange or bdTransaction are specified, and input or parse_file is called the entire document will be parsed, with only the specified section being saved in memory at any given time. This means if you wish to set x_path to navigate within the section of the document, you will need to do so within the events of the class to prevent further processing of the document while you access the section. When parsing is completely, only the most recently parsed section will be available for use with x_path

    If bdNone is specified, then all document information must be obtained through the events fired during parsing.

During parsing, the class performs basic validation of the incoming document. If validation fails, a warning is generated (fired as an event).

The XPath navigation is done through the x_path property. For example:

EDIReader.XPath = "/IX[1]/FG[1]/TX[2]/N1Loop1[1]/N1[1]";
This example path means the following: Select the first N1 segment within the first iteration of the N1Loop1, within second transaction in the first functional group and interchange.

You can also make use of XPath conditional statements to locate the first element which matches a name=value. For example, you could use the following XPath to locate the path of the first element within any N1Loop1 that has a name=N101 and value=BT:

EDIReader.XPath = "IX[1]/FG[1]/TX[1]/N1Loop1[N101='BT']";

Note that the conditional statements will search the children, but not the grand children of the element on which the conditional statement is applied. For instance in the above example the children of N1Loop1 will be searched, but the grandchildren will not.

Additionally if the schema loaded is a ArcESB JSON schema the element Id (from the schema) can be used in the conditional statement. For instance instead of N101 the following is also acceptable:

EDIReader.XPath = "IX[1]/FG[1]/TX[1]/N1Loop1[98='BT']";

To display the structure of the parsed document use display_schema_info. This is helpful when deciding how to navigate the document.

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

build_domWhen True, an internal object model of the EDI document is created.
edi_standard_versionThe version of the EDI specification.
extra_dataExtra data that has not been parsed by the class.
input_dataThe data to parse.
input_fileThe file to parse.
offsetCurrent offset of the document being parsed.
schema_formatThe format of the schema file.
x_childrenNumber of child elements of the current segment.
element_countThe number of records in the Element arrays.
element_component_countNumber of classes in the current element.
element_component_indexThe index of the selected class of the current element.
element_component_nameThe name of the class selected by ClassIndex , according to the Transaction Set schema.
element_component_schema_descThe textual description of the class from the loaded ArcESB JSON schema.
element_component_schema_nameThe name of the class as taken from the schema.
element_component_typeThe data type of class selected by ClassIndex , according to the Transaction Set Schema.
element_component_valueThe value of the class selected by ClassIndex .
element_data_typeThe data type of this EDI element, according to the Transaction Set Schema.
element_nameThe name of this EDI element, according to the Transaction Set schema.
element_repeat_countThe number of times this element is repeated in the in the segment.
element_repeat_indexThe index of the selected instance of this repeatable element.
element_schema_descThe textual description of the element from the loaded ArcESB JSON schema.
element_schema_nameThe name of the element as taken from the schema.
element_valueThe value directly associated with this EDI element.
x_pathProvides a way to point to a specific segment in the document.
x_segmentThe name of the current segment.
x_segment_numberThe number of the current segment.
x_segment_typeIndicates the current segment type.
x_tagThe tag of the current segment.
x_transaction_codeThe transaction code of the current segment.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

compile_schemaCompiles an existing XSD schema into an optimized binary representation.
configSets or retrieves a configuration setting.
display_schema_infoReturns a string showing the structure of the schema defining the document.
display_xml_infoReturns a string showing the structure of the parsed document as XML.
flushFlushes the parser and checks its end state.
generate_ackGenerates an EDI acknowledgement.
has_x_pathDetermines whether a specific element exists in the document.
load_schemaLoads a schema file describing a Transaction Set.
parseParse the specified input data.
resetResets the parser.
try_x_pathNavigates to the specified XPath if it exists.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

on_end_functional_groupFires whenever a control segment is read that marks the end of an interchange.
on_end_interchangeFires whenever a control segment is read that marks the end of an interchange.
on_end_loopFires when the end of a loop is detected in a transaction set.
on_end_transactionFires whenever a control segment is read that marks the end of a transaction.
on_errorInformation about errors during data delivery.
on_resolve_schemaFires whenever a new transaction set is encountered and no schema is found for it.
on_segmentFires whenever a data segment in a transaction set is read.
on_start_functional_groupFires whenever a control segment is read that marks the start of a functional group.
on_start_interchangeFires whenever a control segment is read that marks the start of an interchange.
on_start_loopFires when the starting of a loop is detected in a transaction set.
on_start_transactionFires whenever a control segment is read that marks the start of a transaction.
on_warningFires whenever a validation warning is encountered.

Configuration Settings


The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.

ComponentDelimiterThe delimiter separating classes.
CrossFieldValidationEnabledEnables cross-field validation rules.
ElementDelimiterThe delimiter character separating data elements.
EncodingThe character encoding to be applied when reading and writing data.
HasXPathDetermines if the specified XPath exists.
ISA11IsRepetitionSeparatorSpecifies whether the ISA11 value is treated as a Repetition Separator or Standard Identifier.
ReleaseCharThe character used to escape delimiters within values.
ResolveXPathOnSetDetermines whether or not the XPath is resolved when set.
SegmentDelimiterThe delimiter character separating segments within the EDI document.
StrictSchemaValidationSpecifies the behavior during schema validation.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
ProcessIdleEventsWhether the class uses its internal event loop to process events when the main thread is idle.
SelectWaitMillisThe length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.
UseInternalSecurityAPITells the class whether or not to use the system security libraries or an internal implementation.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks EDI 2020 Python Edition - Version 20.0 [Build 8203]