我正在爲BizTalk 2013中的平面文件反彙編開發一個模式。但是,由於解析結果是垃圾,所以我對模式有很大的問題。 平面文件類型我解析如下所示:如何解析可選字段從左向右與BizTalk平面文件分析器設置爲複雜?
HEADER:opt1:opt2:opt3+opt4:opt5+opt6+op7:opt8:opt9'
TAG1:opt1:opt2:opt3+opt4:opt5:opt6+op7:opt8:opt9'
TAG2:opt1:opt2:opt3+opt4:opt5:opt6+op7:opt8:opt9'
TAG3:opt1:opt2:opt3+opt4++opt6+op7:opt8:opt9'
TAG4:opt1:opt2:opt3+opt4:opt5'
平面文件有三個層次的部分:
頂級:段,通過「字符(不換行分隔,這是隻是爲了更好的可讀性而添加)
中級別:字段,用+字符分隔。可以直接地包含一個值或一組值(見底部電平)
底部級別:屬性,通過分隔:字符
由於TAG? - 部分是可選的,可能發生在多個命令中,我使用parser_optimization =「complexity」選項以及lookahead_depth =「0」並使用TAG? - 用於標識段類型,我用於解析所有內容。 所有分隔符都是child_order =「infix」,除了這些段是child_order =「postfix」。
某些分段,字段和屬性是必需的,大多數不是。但是,始終需要第一個字段及其屬性(標記名稱,...)。 段的分離和識別工作正常,字段也正常工作。但是,當我有包含一組可選屬性的可選字段時,架構無法正確解析。 舉例: 語法:
TAGX:opt1:opt2:opt3+a1:a2:a3:a4:a5:a6'
所有一個?屬性是可選的
屬性值被投入到正確的XML字段在解析這樣的段:
TAGX:1:2:3+:1:2:::'
然而,因爲平面文件規範允許可選字段被排除在外,則消息也可能是這樣的:
TAGX:1:2:3+:1:2'
在這種情況下,該值沒有被置於第二和第三場XML像他們應該是,但是被放入第三和第四位。根據包含在該段中的標誌數量,也可以填寫第一個和第六個或第二個和第四個XML字段。
我需要平面文件分析器來填充這些字段從左到右,而不是現在使用的混沌方式。但是,切換到parser_optimization =「speed」不是一個選項,因爲其他模式過於複雜(除非有本地執行的方法)。
這些都是被用來解析這種字段XSD架構的部分(僅限於所提取的部分,因爲該架構是非常大的)
公用部分的定義(被包含在模式本身,是正在使用的其他模式,以及,在本例中爲4部分的屬性組):
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:annotation>
<xs:appinfo>
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions"/>
<b:schemaInfo root_reference="SEG_HEAD" pad_char_type="none" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" standard="Flat File" default_pad_char=" "/>
</xs:appinfo>
</xs:annotation>
<xs:element name="MATERIAL_TYPE" type="MATERIAL_TYPE">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="4" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="char" child_delimiter=":" escape_char_type="char" escape_char="?" child_order="infix"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:complexType name="MATERIAL_TYPE">
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="NUMBER_SYSTEM" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="MATERIAL" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="2" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="EAN" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="3" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="BUYERARTICLENUMBER" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="4" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
特定的模式提取物:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://example.com/namespace" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation=".\COMMON_SChema_v2.0.xsd"/>
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="SEG_ORDER" pad_char_type="none" count_positions_by_byte="false" parser_optimization="complexity" lookahead_depth="0" suppress_empty_nodes="true" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" default_pad_char=" " escape_char_type="char" default_escape_char="?" default_child_order="infix"/>
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="SEG_ORDER">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_order="postfix" escape_char_type="char" escape_char="?" sequence_number="17" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="char" child_delimiter="'"/>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="TAGX" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="+" child_order="infix" escape_char_type="char" escape_char="?" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="6" tag_name="TAGX"/>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="SEG_HEAD" type="SEG_HEAD_REF1_TYPE">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=":" escape_char_type="char" escape_char="?" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_order="prefix"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="POSITION_NUMBER">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=":" child_order="infix" escape_char_type="char" escape_char="?" sequence_number="2" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false"/>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="NUMBER" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="1"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="MATERIAL" type="MATERIAL_TYPE" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=":" child_order="infix" escape_char_type="char" escape_char="?" sequence_number="3" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
看你的例子中,第一場記錄應具有前綴,而不是作爲綴有選項1一個:之前。 – Dijkgraaf
您在SEG_HEAD定義中有一個錯誤的行。對於字符串類型的元素,您有。這是無效的。 – Dijkgraaf