我有两种类型的平面文件行,
以@
开头,例如@111 222 333
以#
开头,例如#777 888 999
我们可以使用标签标识符来识别这两种类型的行。不幸的是,这两行可能会出现在文件的任何序列中,例如@@###
,@#@#@
或###@@
等。
如果使用平面文件解析器架构,似乎序列必须按顺序排列,比如@@@##
,@##
,它可以将所有平面文件内容反汇编成XML格式。
但如果文件格式为@@#@@#
或@###@#
,则无法解析所有文件内容并停在中间位置,例如@@#@@#
只能反汇编@@#
,{ {1}}只能反汇编@###@#
。
我认为这是因为平面文件架构指定序列为@###
然后@
,因此,#
无法显示@
(如果我的理解,请告知是错的)。
我们案件的任何解决方案?
感谢。
答案 0 :(得分:1)
将标记记录放在可能多次出现的选择组下。 见下面的例子。
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.FlatFileSchemaRandomTagOrder" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.FlatFileSchemaRandomTagOrder" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Root" default_pad_char=" " pad_char_type="char" 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" />
<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="Root">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:element name="RecordHash">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" tag_name="#" child_order="infix" 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="Field1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Field2" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Field3" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="3" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="RecordAt">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="2" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="@" child_order="infix" 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="Field1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Field2" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Field3" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="3" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
示例文件
@111 222 333
#777 888 999
@111 222 333
输出
<Root xmlns="http://Scratch.FlatFileSchemaRandomTagOrder">
<RecordAt xmlns="">
<Field1>111</Field1>
<Field2>222</Field2>
<Field3>333</Field3>
</RecordAt>
<RecordHash xmlns="">
<Field1>777</Field1>
<Field2>888</Field2>
<Field3>999</Field3>
</RecordHash>
<RecordAt xmlns="">
<Field1>111</Field1>
<Field2>222</Field2>
<Field3>333</Field3>
</RecordAt>
</Root>