带有逗号的包装字段的不匹配包装字符

Unmatched wrap character for a wrapped field with comma in it

我有这个 CSV 输入:

Username,"Certification ID number","Certification Name","Date completed","Date due"

nlxxxxxx,NLaaa,"NL - Test certificaat",1/12/2021,"15/12/2022, 07:55"

nlyyyyyy,CPbbb-cert,"Test Law certificaat",1/12/2021,"30/11/2023, 09:10"

我从 BizTalk Test Mapper 得到以下错误:

error btm1041: Native Parsing Error: Unmatched wrap character " The current definition being parsed is Certificate. The stream offset where the error occured is 153. The line number where the error occured is 2. The column where the error occured is 68.

我假设错误来自 Date due 字段。我用 wrap character 属性 设置了这个字段(见下面的 XSD)。

<?xml version="1.0" encoding="utf-16" ?> 
<xs:schema xmlns="http://Securitas.ESB.HR.LMSToAfas_ManageCertificate.Schemas.LMSCertificate" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Securitas.ESB.HR.LMSToAfas_ManageCertificate.Schemas.LMSCertificate" 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="LMSCertificate" /> 
        </xs:appinfo>
    </xs:annotation>
    <xs:element name="LMSCertificate">
        <xs:annotation>
            <xs:appinfo>
                <b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="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="Header">
                    <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="Username" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="1" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="CertificationID" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="2" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="CertificationName" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="3" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="DateCompleted" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="4" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="DateDue" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="5" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element maxOccurs="unbounded" name="Certificate">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="," 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 name="Username" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="1" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="CertificationID" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="2" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="CertificationName" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="3" wrap_char_type="char" wrap_char=""" pad_char_type="hex" pad_char="0x20" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="DateCompleted" type="xs:date">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="4" pad_char_type="hex" pad_char="0x20" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="DateDue" type="xs:dateTime">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="5" wrap_char_type="char" wrap_char=""" pad_char_type="none" /> 
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

我想不通我哪里错了

首先你需要检查你的行以什么结尾,你已经将它定义为LF,但如果它是CR LF,它会抛出上面的错误。在根节点上将其更改为 0x0D 0x0A。

如果您随后得到以下内容,那么最后一行没有分隔符,您需要将根节点 LMS 证书上的子顺序更改为 Infix。

The current definition being parsed is Certificate. The stream offset where the error occured is 227. The line number where the error occured is 3. The column where the error occured is 72.

接下来你会得到以下错误

The 'DateCompleted' element is invalid - The value '1/12/2021' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:date' - The string '1/12/2021' is not a valid Date value.
The 'DateDue' element is invalid - The value '15/12/2022, 07:55' is invalid according to its datatype 'DateTime' - The string '15/12/2022, 07:55' is not a valid DateTime value.
The 'DateCompleted' element is invalid - The value '1/12/2021' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:date' - The string '1/12/2021' is not a valid Date value.
The 'DateDue' element is invalid - The value '30/11/2023, 09:10' is invalid according to its datatype 'DateTime' - The string '30/11/2023, 09:10' is not a valid DateTime value.

将 DateCompleted 自定义 Date/Time 格式设置为 d/MM/yyyy,这将消除两个错误。

现在 DueDate 有点棘手,我尝试了 d/MM/yyyy, hh:mm 的自定义 Date/Time 格式,但它没有用,仍然抛出了同样的两个错误。如果我将它更改为 String,它会正确解析。一个线索是当我生成一个本机实例时它会将它填充为 DueDate。在我复制了您的其他日期并重命名后,将其更新为 DateTime 并更新了它工作的自定义格式。

差异

  • child_delimiter="0x0D 0x0A" 获得 LMSCertificate
  • 不确定当您发布到 StackOveflow 时是否已损坏,但 wrap_char=""" 无效,应该是 wrap_char="&quot;"
  • datetime_format="d/MM/yyyy" 完成日期
  • pad_char_type="hex" pad_char="0x20" datetime_format="d/MM/yyyy, hh:mm" 截止日期
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Securitas.ESB.HR.LMSToAfas_ManageCertificate.Schemas.LMSCertificate" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Securitas.ESB.HR.LMSToAfas_ManageCertificate.Schemas.LMSCertificate" 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" 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="LMSCertificate" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="LMSCertificate">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" 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="Header">
          <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="Username" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="CertificationID" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="CertificationName" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="DateCompleted" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="4" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="DateDue" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="5" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="Certificate">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="," 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 name="Username" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="CertificationID" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="CertificationName" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" wrap_char_type="char" pad_char_type="hex" pad_char="0x20" wrap_char="&quot;" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="DateCompleted" type="xs:date">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="4" pad_char_type="hex" pad_char="0x20" datetime_format="d/MM/yyyy" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="DateDue" type="xs:dateTime">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" pad_char_type="hex" pad_char="0x20" datetime_format="d/MM/yyyy, hh:mm" sequence_number="5" wrap_char_type="char" wrap_char="&quot;" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

输出

<LMSCertificate xmlns="http://Securitas.ESB.HR.LMSToAfas_ManageCertificate.Schemas.LMSCertificate">
    <Header xmlns="">
        <Username>Username</Username>
        <CertificationID>"Certification ID number"</CertificationID>
        <CertificationName>"Certification Name"</CertificationName>
        <DateCompleted>"Date completed"</DateCompleted>
        <DateDue>"Date due"</DateDue>
    </Header>
    <Certificate xmlns="">
        <Username>nlxxxxxx</Username>
        <CertificationID>NLaaa</CertificationID>
        <CertificationName>NL - Test certificaat</CertificationName>
        <DateCompleted>2021-12-01</DateCompleted>
        <DateDue>2022-12-15T07:55:00.0000000</DateDue>
    </Certificate>
    <Certificate xmlns="">
        <Username>nlyyyyyy</Username>
        <CertificationID>CPbbb-cert</CertificationID>
        <CertificationName>Test Law certificaat</CertificationName>
        <DateCompleted>2021-12-01</DateCompleted>
        <DateDue>2023-11-30T09:10:00.0000000</DateDue>
    </Certificate>
</LMSCertificate>

P.S。我还假设你的示例中的额外行是由于尝试为 Whosebug 格式化它,它实际上看起来像这样

Username,"Certification ID number","Certification Name","Date completed","Date due"
nlxxxxxx,NLaaa,"NL - Test certificaat",1/12/2021,"15/12/2022, 07:55"
nlyyyyyy,CPbbb-cert,"Test Law certificaat",1/12/2021,"30/11/2023, 09:10"