简体   繁体   English

BizTalk - 为带有位置分隔符的平面文件构建 XSD

[英]BizTalk - Build XSD for flat file with positional delimiter

I am trying to build XSD file for converting a flat file (which does not have any delimiters) to xml file.我正在尝试构建 XSD 文件以将平面文件(没有任何分隔符)转换为 xml 文件。

Below is the sample data:以下是样本数据:

0000000020220709200012000000  000000000  000000000  000000000  000000000             
002029832022070922162607090111057992132                                 F        
00210018202207091911210709033S061991911DS0649919111S067891911           F   
9999999900000000000020000000  000000000  000000000  000000000  000000000      
Column柱子 Start Position启动 Position End Position结束 Position
Area区域 0 0 8 8
Date日期 9 9 16 16
Number of records in the line (this determines how many Change values are present in this line)行中的记录数(这决定了该行中存在多少更改值) 27 27 28 28
Change 1变化 1 31 31 25 25
Change 2 (+11 positions from above)更改 2 (从上方 +11 个位置) 42 42 46 46
Change 3 (+11 positions from above)更改 3 (从上方 +11 个位置) 53 53 57 57

In the above sample data, I want to eliminate first & last lines.在上面的示例数据中,我想消除第一行和最后一行。 Can anyone help me in sample XSD for the above data which gives me below output:任何人都可以在样本 XSD 中帮助我获取上述数据,这给了我低于 output 的数据:

<Lookup_Value_Set>
     <Record>
          <Area>00202983</Area>
          <Date>20220709</Date>
          <Change>05799</Change>
     </Record>
     <Record>
          <Area>00210018</Area>
          <Date>20220709</Date>
          <Change>06199</Change>
     </Record>
     <Record>
          <Area>00210018</Area>
          <Date>20220709</Date>
          <Change>06499</Change>
     </Record>
</Lookup_Value_Set>

I have been stuck here for a week now:-(. Not able to determine what the delimiter for line should be & how I can skip first & last lines.我已经在这里呆了一个星期了:-(。无法确定行的分隔符应该是什么以及如何跳过第一行和最后一行。

Additional context:附加上下文:

  • The file is from linux machine.该文件来自 linux 机器。 So line breaks are LF & not CR LF所以换行符是 LF 而不是 CR LF
  • IMPORTANT: The file has additional spaces beyond the last character ( total characters are 100 in a line but data is filled till position 73 )重要提示:该文件在最后一个字符之外有额外的空格(总字符为 100 行,但数据填充到 position 73
  • Using xmlns="http://schemas.microsoft.com/BizTalk/2003"使用 xmlns="http://schemas.microsoft.com/BizTalk/2003"
  • From what ever testing I did, I always end up with below error从我所做的任何测试来看,我总是会遇到以下错误

Decoding of the flat file failed: 'Unexpected data found while looking for: '\n' The current definition being parsed is Lookup_Value_Set.平面文件解码失败:'查找时发现意外数据:'\n' 当前正在解析的定义是 Lookup_Value_Set。 The stream offset where the error occured is 75发生错误的stream偏移量为75

Any help is greatly appreciated.任何帮助是极大的赞赏。

With the below schema, it will parse the file and be close to what you want.使用以下架构,它将解析文件并接近您想要的。 It doesn't break the change2 etc. into it's own record, but you can do that in a map.它不会将 change2 等打破到它自己的记录中,但您可以在 map 中做到这一点。 I've not done change3, but you can add and amend that.我还没有做 change3,但你可以添加和修改它。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.Schema.SO73481712" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.Schema.SO73481712" 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="complexity" 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="0x0A" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:annotation>
          <xs:appinfo>
            <b:groupInfo sequence_number="0" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element name="Header">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Field" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="1" justification="left" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="Record">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="2" child_order="postfix" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Area" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" pos_length="8" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Date" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="2" justification="left" pos_length="8" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Changes" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" pos_length="1" pos_offset="10" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Change1" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="4" pos_length="5" pos_offset="3" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element minOccurs="0" name="Change2" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="5" pos_length="5" pos_offset="6" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Field" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="6" pos_length="26" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="F" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="7" pos_length="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element minOccurs="0" maxOccurs="unbounded" name="Hungry" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" pos_length="1" sequence_number="8" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Footer">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo sequence_number="3" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="9" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Field" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="1" justification="left" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

You will get the below output您将获得以下 output

<Root xmlns="http://Scratch2.Schema.SO73481712">
    <Header xmlns="">
        <Field>0000000020220709200012000000  000000000  000000000  000000000  000000000</Field>
    </Header>
    <Record xmlns="">
        <Area>00202983</Area>
        <Date>20220709</Date>
        <Changes>0</Changes>
        <Change1>05799</Change1>
        <Change2/>
        <Field/>
        <F>F</F>
        <Hungry/>
        <Hungry/>
        <Hungry/>
        <Hungry/>
        <Hungry/>
        <Hungry/>
        <Hungry/>
        <Hungry/>
    </Record>
    <Record xmlns="">
        <Area>00210018</Area>
        <Date>20220709</Date>
        <Changes>0</Changes>
        <Change1>06199</Change1>
        <Change2>06499</Change2>
        <Field>19111S067891911</Field>
        <F>F</F>
        <Hungry/>
        <Hungry/>
        <Hungry/>
    </Record>
    <Footer xmlns="">
        <Field>999999900000000000020000000  000000000  000000000  000000000  000000000</Field>
    </Footer>
</Root>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM