简体   繁体   English

BizTalk - 在记录的开头和结尾使用单词分隔符为平面文件构建 XSD

[英]BizTalk - Build XSD for flat file with words delimiter at start and end of records

I am trying to build an XSD file based on the following text file (flat file).我正在尝试基于以下文本文件(平面文件)构建 XSD 文件。 I am using the flat file schema wizard but can't achieve what I want.我正在使用平面文件模式向导,但无法实现我想要的。

:BEGIN
Key1 Value1
Key2 Value2
:END
:BEGIN
Key1 Value1
Key2 Value2
Key3 Value3
:END
:BEGIN
:END

The XSD would be something like : XSD 将类似于:

Record (Delimited by :BEGIN and :END)
|_Association (Delimited by \n)
  |_Key (Delimited by space, first occurence)
  |_Value (second occurence)

I would like my txt file to be transformed as an instance of the xsd file in xml.我希望我的 txt 文件被转换为 xml 中 xsd 文件的一个实例。 The result would be something like :结果将是这样的:

<Record>
  <Association>
    <Key>Key1</Key>
    <Value>Value1</Value>
  </Association>
  <Association>
    <Key>Key2</Key>
    <Value>Value2</Value>
  </Association>
</Record>
<Record>
  <Association>
    <Key>Key1</Key>
    <Value>Value1</Value>
  </Association>
  <Association>
    <Key>Key2</Key>
    <Value>Value2</Value>
  </Association>
  <Association>
    <Key>Key3</Key>
    <Value>Value3</Value>
  </Association>
</Record>

There is only 2 records because last :BEGIN:END block is empty.只有 2 条记录,因为最后一个 :BEGIN:END 块是空的。

My main issue is that I can't find out how to delimit my records by :START and :END tags.我的主要问题是我无法找到如何通过 :START 和 :END 标记分隔我的记录。 Is that even possible ?这甚至可能吗?

Yes, it is possible to do, but not with the Wizard.是的,可以这样做,但不能使用向导。 It is a matter of manually building it up and testing the structure as you add definitions.这是在添加定义时手动构建和测试结构的问题。

It is a matter of using Tag Identifiers for the :BEGIN and :END as well using a Sequence Group to say that these re-occur.使用 :BEGIN 和 :END 的标签标识符以及使用序列组来说明这些重新出现是一个问题。

Additionally at the <Schema> level set Parser Optimization to Complexity.此外,在<Schema>级别将 Parser Optimization 设置为 Complexity。

Depending on what defines the end of your line, you may need to adjust the 0x0A 0x0D (Carriage Return & Line Feed) to what your file actually contains.根据定义行尾的内容,您可能需要将 0x0A 0x0D(回车和换行)调整为文件实际包含的内容。 Also if the last line does not finish with a CR/LF then change it from being Postfix (after) to Infix (between).此外,如果最后一行没有以 CR/LF 结束,则将其从后缀(后)更改为中缀(之间)。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.SO63600733" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.SO63600733" 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" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:annotation>
          <xs:appinfo>
            <b:groupInfo sequence_number="0" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element maxOccurs="unbounded" name="Record">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" 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:sequence>
                <xs:annotation>
                  <xs:appinfo>
                    <b:groupInfo sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
                <xs:element name="BEGIN">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" tag_name=":BEGIN" />
                    </xs:appinfo>
                  </xs:annotation>
                  <xs:complexType />
                </xs:element>
                <xs:element minOccurs="0" maxOccurs="unbounded" name="Accociation">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="char" child_order="infix" child_delimiter=" " sequence_number="2" />
                    </xs:appinfo>
                  </xs:annotation>
                  <xs:complexType>
                    <xs:sequence>
                      <xs:annotation>
                        <xs:appinfo>
                          <b:groupInfo sequence_number="0" />
                        </xs:appinfo>
                      </xs:annotation>
                      <xs:element name="Key" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <b:fieldInfo sequence_number="1" justification="left" />
                          </xs:appinfo>
                        </xs:annotation>
                      </xs:element>
                      <xs:element name="value" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <b:fieldInfo sequence_number="2" justification="left" />
                          </xs:appinfo>
                        </xs:annotation>
                      </xs:element>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
                <xs:element name="END">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name=":END" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0A 0x0D" sequence_number="3" />
                    </xs:appinfo>
                  </xs:annotation>
                  <xs:complexType />
                </xs:element>
              </xs:sequence>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

With your example input gives使用您的示例输入给出

<Root xmlns="http://Scratch.SO63600733">
    <Record xmlns="">
        <BEGIN/>
        <Accociation>
            <Key>Key1</Key>
            <value>Value1</value>
        </Accociation>
        <Accociation>
            <Key>Key2</Key>
            <value>Value2</value>
        </Accociation>
        <END/>
    </Record>
    <Record xmlns="">
        <BEGIN/>
        <Accociation>
            <Key>Key1</Key>
            <value>Value1</value>
        </Accociation>
        <Accociation>
            <Key>Key2</Key>
            <value>Value2</value>
        </Accociation>
        <Accociation>
            <Key>Key3</Key>
            <value>Value3</value>
        </Accociation>
        <END/>
    </Record>
    <Record xmlns="">
        <BEGIN/>
        <END/>
    </Record>
</Root>

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

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