Biztalk平面文件架构分隔符

时间:2014-04-15 17:52:00

标签: biztalk

我有一个类似于以下内容的flatfile:

brand: bmw {CR}{LF}    
{CR}{LF}
engine: 2000cc {CR}{LF}    
{CR}{LF}
description: bla bla{CR}{LF}
{CR}{LF}
bla bla bla{CR}{LF}
bla bla bla{CR}{LF}
{CR}{LF}
bla{CR}{LF}
{CR}{LF}
remarks: none

要分隔品牌,引擎,说明和备注,我可以使用" {CR} {LF} {CR} {LF}",但由于说明包含" {CR} { LF} {CR} {LF}"此外,它可以是描述中的任意数量的行。

我想得到一个xml:

<brand>bmw</brand>
<engine>2000cc</engine>
<description>bla bla{CR}{LF}{CR}{LF}bla bla bla{CR}{LF}{CR}{LF}bla bla ....</description>
<remarks>none</remarks>

这是否可以使用flatfile架构?

1 个答案:

答案 0 :(得分:3)

您最初可能无法在描述中保留CR LF,但是您可以创建一个允许您在之后重新组合它的结构。

1)使用标签来识别包含第一条描述线的标签。 2)为后续描述行创建一个没有标记的重复记录。 3)然后,您可以使用累积连接将两组描述行映射到目标模式中,然后添加换行符。

请参阅下面的示例模式。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.Car" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.Car" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo standard="Flat File" root_reference="Car" 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="Car">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="infix" 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:element name="Brand">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo sequence_number="1" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="brand: " />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="BrandName" 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 name="Empty1">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo sequence_number="2" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType />
        </xs:element>
        <xs:element name="Engine">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="engine: " sequence_number="3" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="EngineType" 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 name="Empty2">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="4" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType />
        </xs:element>
        <xs:element name="Description">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo sequence_number="5" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="description:" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="DescriptionLine" 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 maxOccurs="unbounded" name="DescriptionCont">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="6" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="DescriptionLine" 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 name="Remarks">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo sequence_number="7" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="remarks: " />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Remark" 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>

这为您提供了

的XML
<?xml version="1.0"?>
<Car xmlns="http://Scratch.Car">
  <Brand xmlns="">
    <BrandName>bmw</BrandName>
  </Brand>
  <Empty1 xmlns=""/>
  <Engine xmlns="">
    <EngineType>2000cc</EngineType>
  </Engine>
  <Empty2 xmlns=""/>
  <Description xmlns="">
    <DescriptionLine> bla bla</DescriptionLine>
  </Description>
  <DescriptionCont xmlns="">
    <DescriptionLine/>
  </DescriptionCont>
  <DescriptionCont xmlns="">
    <DescriptionLine>bla bla bla</DescriptionLine>
  </DescriptionCont>
  <DescriptionCont xmlns="">
    <DescriptionLine>bla bla bla</DescriptionLine>
  </DescriptionCont>
  <DescriptionCont xmlns="">
    <DescriptionLine/>
  </DescriptionCont>
  <DescriptionCont xmlns="">
    <DescriptionLine>bla</DescriptionLine>
  </DescriptionCont>
  <DescriptionCont xmlns="">
    <DescriptionLine/>
  </DescriptionCont>
  <Remarks xmlns="">
    <Remark>none</Remark>
  </Remarks>
</Car>

目标架构

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="car">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="brand" type="xs:string" />
        <xs:element name="engine" type="xs:string" />
        <xs:element name="description" type="xs:string" />
        <xs:element name="remarks" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

地图 Mapping the Car data

输出。

<car>
<brand>bmw</brand>
<engine>2000cc</engine>
<description>bla bla{CR}{LF}{CR}{LF}bla bla bla{CR}{LF}{CR}{LF}bla bla ....</description>
<remarks>none</remarks>
</car>

P.S。我将文字{CR} {LF}放入连接functoid而不是CR&amp; LF字符。要获得真实的,请使用返回System.Environment.NewLine的脚本functoid;它传递给两个连接functoid。