2

给定管道分隔的文档:

HDR|A
PSN|CCC|111|00|111111111|DOE|JOHN||M
PSN|CCC|111|01|111111111|DOE|JANE|A|F|07/30/1975
ADR|CCC|111|00|U|100 S 1ST #11||ANYTOWN|US|XX|55555|09/24/2013|
PHN|CCC|111|00|U|US|5551111111||09/24/2013|

和 BizTalk 架构:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://xxxx.com/schemas/test1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://xxxx.com/schemas/test1" 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="complexity" lookahead_depth="0" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="true" early_terminate_optional_fields="true" 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_order="postfix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="true" child_delimiter="0x0D 0x0A" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          <xs:appinfo>
            <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element minOccurs="1" maxOccurs="1" name="Header" type="HeaderType">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="|" child_order="infix" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="HDR" tag_offset="0" sequence_number="1" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="Person" type="PersonType">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" tag_name="PSN" tag_offset="0" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="char" child_delimiter="|" sequence_number="2" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="Address" type="AddressType">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" tag_name="ADR" tag_offset="0" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="char" child_delimiter="|" sequence_number="3" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="Phone" type="PhoneType">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" tag_name="PHN" tag_offset="0" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="char" child_delimiter="|" sequence_number="4" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="HeaderType">
    <xs:attribute default="" name="type" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="1" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="description" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="2" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
  <xs:complexType name="PersonType">
    <xs:attribute name="group" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="1" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="id" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="2" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="seq" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="3" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="ssn" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="4" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="last" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="5" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="first" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="6" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="mi" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="7" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="gender" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="8" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="dob" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="9" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
  <xs:complexType name="AddressType">
    <xs:attribute name="group" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="1" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="id" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="2" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="seq" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="3" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="type" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="4" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="addr1" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="5" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="addr2" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="6" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="city" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="7" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="country" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="8" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="state" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="9" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="zip" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="10" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="date" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="11" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="filler" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="12" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
  <xs:complexType name="PhoneType">
    <xs:attribute name="client_code" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="1" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="id" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="2" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="seq" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="3" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="type" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="4" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="country" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="5" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="number" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="6" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="extension" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="7" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="date" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="8" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute default="" name="filler" type="xs:string">
      <xs:annotation>
        <xs:appinfo>
          <b:fieldInfo justification="left" sequence_number="9" />
        </xs:appinfo>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>
</xs:schema>

其中“choice”用于根(因为子记录可以按任何顺序排列),其中“tag_name”用于将记录与模式元素匹配。

并通过 fadsm 实用程序运行

ffdasm "test1.psv" -bs "test1.xsd" -s -m "test1.xml" -v -s

得到这个

- <Root xmlns="http://xxxx.com/schemas/test1">
  <Header type="" description="A" xmlns="" /> 
  <Person group="CCC" id="111" seq="00" ssn="111111111" last="DOE" first="JOHN" mi="" gender="M PSN" dob="CCC|111|01|111111111|DOE|JANE|A|F|07/30/1975" xmlns="" /> 
  <Address group="CCC" id="111" seq="00" type="U" addr1="100 S 1ST #11" addr2="" city="ANYTOWN" country="US" state="XX" zip="55555" date="09/24/2013" filler="" xmlns="" /> 
  <Phone client_code="CCC" id="111" seq="00" type="U" country="US" number="5551111111" extension="" date="09/24/2013" filler="" xmlns="" /> 
  </Root>
  • 为什么标头 (HDR) 记录的第一个字段值 ("A") 进入输出 XML 的错误(第二个)属性?

  • 为什么在为提前终止记录和可选字段设置架构时,记录分隔符 (CRLF / 0x0D ox0A) 会被忽略,以便第二个 (PSN) 记录的内容进入结果 XML 中先前记录的可选属性?

顺便说一句

  • 为什么分隔文件的输出 XML 中省略了“tag_name”匹配的内容?固定长度的平面文件不会发生这种情况;其中,tag_name 数据保留在输出中。

非常感谢任何见解。

4

1 回答 1

1

由于您定义的中缀的 child_order,HDR 中的第一个字段将转到第二个字段。子顺序共有三个,前缀、中缀、后缀。

前缀表示分隔符出现在每个字段之前。|1|2|3

中缀意味着它出现在每个字段之间。1|2|3

后缀意味着它出现在每个字段之后。1|2|3|

现在您选择了中缀。所以让我们看看你的线路。

HDR|A

你已经告诉它标签是 HDR,所以它会去掉它并留下

|A

因为它是中缀,所以 | 之前是什么 是字段 1,之后是字段 2。

你想要的是前缀。

正如您所观察到的,标签名称被删除,它们被视为记录名称。

至于记录分隔符被忽略,这是平面文件反汇编程序的一个坏习惯,如果它确实期望另一个它找不到的字段,然后它会消耗下一行以使其进入该字段。再次检查您正在执行的子订单类型以及字段是否正确匹配。

于 2013-09-29T07:10:05.847 回答