문제

I have a flatfile that looks something like the following:

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

To delimiter brand, engine, description and remarks, i could use "{CR}{LF}{CR}{LF}", but since description is containing "{CR}{LF}{CR}{LF}" aswell, and it could be any number of rows in description.

I would like to get an xml like:

<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>

Is this possible with a flatfile schema?

도움이 되었습니까?

해결책

You probably won't be able to preserve the CR LF in the description initially, however you could create a structure that would allow you to re-assemble it afterwards.

1) Use tags to identify those that have them including the first description line. 2) Have a repeating record without a tag for the subsequent Description lines. 3) You can then map the two sets of description lines together into your target schema using the Cumulative Concatenate and adding the line breaks back in.

See sample schema below.

<?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>

This gives you XML of

<?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>

Target schema

<?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>

Map Mapping the Car data

And the output.

<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. I put literal {CR}{LF} into the concatenate functoid rather than the CR & LF characters. To get the real ones use a scripting functoid that has return System.Environment.NewLine; that passed it to both concatenate functoids.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top