如何设置2个字符作为换行符?

时间:2017-09-07 15:15:08

标签: csv xsd biztalk

如何为csv-file创建一个BizTalk平面文件XSD架构,它使用两个引号("")作为换行符,并用相同的单个数据包装每个行数据(除了标题)字符(")?

例如:

header1,header2,header3,header4
"text1,""68,12"",""32,11"",""69,38"""
"text2,,""13,71"",""123,56"""
"text3,""12,75"",,""732,87"""
"text4,""147,14"",""65,43"","

2 个答案:

答案 0 :(得分:1)

这不是一个有效的CSV结构*,所以你将遇到100%正确的问题。

*由于您的部分逗号位于引号内,逗号组之间没有引号

我可以创建的最接近的模式将成功解析,下面我将引用视为行的分隔符。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.46099894" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.46099894" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
      <b:schemaInfo standard="Flat File" codepage="65001" 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" root_reference="Root" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Root">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="0xD 0xA" child_order="postfix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:annotation>
          <xs:appinfo>
            <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element name="Root_Child1">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="," child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Root_Child1_Child1" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Root_Child1_Child2" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Root_Child1_Child3" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Root_Child1_Child4" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="4" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="Root_Child2">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="&quot;" child_order="infix" sequence_number="2" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element maxOccurs="unbounded" name="Root_Child2_Child1" 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:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

其中给出以下结果

<Root xmlns="http://Scratch.46099894">
    <Root_Child1 xmlns="">
        <Root_Child1_Child1>header1</Root_Child1_Child1>
        <Root_Child1_Child2>header2</Root_Child1_Child2>
        <Root_Child1_Child3>header3</Root_Child1_Child3>
        <Root_Child1_Child4>header4</Root_Child1_Child4>
    </Root_Child1>
    <Root_Child2 xmlns="">
        <Root_Child2_Child1/>
        <Root_Child2_Child1>text1,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>68,12</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>32,11</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>69,38</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1/>
        <Root_Child2_Child1/>
    </Root_Child2>
    <Root_Child2 xmlns="">
        <Root_Child2_Child1/>
        <Root_Child2_Child1>text2,,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>13,71</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>123,56</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1/>
        <Root_Child2_Child1/>
    </Root_Child2>
    <Root_Child2 xmlns="">
        <Root_Child2_Child1/>
        <Root_Child2_Child1>text3,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>12,75</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>,,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>732,87</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1/>
        <Root_Child2_Child1/>
    </Root_Child2>
    <Root_Child2 xmlns="">
        <Root_Child2_Child1/>
        <Root_Child2_Child1>text4,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>147,14</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>,</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>65,43</Root_Child2_Child1>
        <Root_Child2_Child1/>
        <Root_Child2_Child1>,</Root_Child2_Child1>
        <Root_Child2_Child1/>
    </Root_Child2>
</Root>

但是,您可能应该首先获取正在创建这些文件的内容以正确格式化它们。

e.g。

header1,header2,header3,header4
"text1","68,12","32,11","69,38"
"text2","","13,71","123,56"
"text3","12,75","","732,87"
"text4","147,14","65,43",""

答案 1 :(得分:0)

您可以使用平面文件架构向导。

1)通过分隔符符号

By delimiter symbol

2)CR LF

CR LF

3)记录标题并重复记录第一项]

Record the Header and Repeating Record the first item

4)通过分隔符符号&#34;,&#34;

By delimiter symbol ","

...