如何将XML转换为平面文件

问题描述 投票:0回答:1

我对集成和中间件非常陌生。我只想将我的XML转换为平面文件。现在,我正在使用Azure Logic Apps进行中间件集成,并使用Maps和Schemas的集成帐户(Azure)。我有一个结构化的XML

<?xml version="1.0" encoding="utf-8"?>
<LOAN_APPLICATION>
    <ADDITIONAL_CASE_DATA_x0020_TRANSMITTAL_DATA>
        <Header>EH</Header>
        <InvestorInstitutionIdentifier></InvestorInstitutionIdentifier>
    </ADDITIONAL_CASE_DATA_x0020_TRANSMITTAL_DATA>
    <VARIABLE_1>
        <Header>TH</Header>
        <Transaction_ID>T100099-002</Transaction_ID>
        <Transaction_Control_Number>2000</Transaction_Control_Number>
    </VARIABLE_1>
    <VARIABLE_2>
        <Header>TPI</Header>
        <Version_ID>1.000</Version_ID>
        <Identify_Type_Code>1</Identify_Type_Code>
        <Identifier></Identifier>
        <Import_Action_Indicator>N</Import_Action_Indicator>
    </VARIABLE_2>
    <VARIABLE_3>
        <Variable>000</Variable>
        <File_Type>1</File_Type>
        <File_Version_ID>3.20</File_Version_ID>
    </VARIABLE_3>
    <MORTGAGE_TERMS>
        <Header>01A</Header>
        <MortgageType>01</MortgageType>
        <AgencyCaseIdentifier />
        <BaseLoanAmount>142500.00</BaseLoanAmount>
        <RequestedInterestRatePercent>5.50</RequestedInterestRatePercent>
        <LoanAmortizationTermMonths>360</LoanAmortizationTermMonths>
        <LoanAmortizationType>05</LoanAmortizationType>
    </MORTGAGE_TERMS>
    <PROPERTY>
        <Header>02A</Header>
        <_StreetAddress>123 TBD</_StreetAddress>
        <_City>zelienople</_City>
        <_State>PA</_State>
        <_PostalCode>16063</_PostalCode>
        <_FinancedNumberOfUnits>3</_FinancedNumberOfUnits>
    </PROPERTY>
    <LOAN_PURPOSE>
        <Header>02B</Header>
        <_Type>16</_Type>
        <PropertyUsageType>1</PropertyUsageType>
        <PropertyRightsType>1</PropertyRightsType>
    </LOAN_PURPOSE>
    <LOAN_PURPOSE_REFINANCE>
        <Header>02D</Header>
        <GSERefinancePurposeType>CashOutH</GSERefinancePurposeType>
    </LOAN_PURPOSE_REFINANCE>
    <DOWN_PAYMENT>
        <Header>02E</Header>
        <_Type>BridgeLoan</_Type>
        <_Amount>1000.00</_Amount>
    </DOWN_PAYMENT>
</LOAN_APPLICATION>

而且我想创建一个这样的平面文件。

EH                                      
TH T100099-0022000         
TPI 1.0001                               N      
0001  3.20     
01A01                                                                                                                             142500.00      5.50   36005                                                                                                                                            
02A123 TBD                                           123 TBD                         PA 16063   3                                                                                   
02B  16                                                                                1                                                            1           
02D                                                                CashOutH
02EF11000.00   

我找不到有关如何执行此操作的任何线索。 我期待XML位置模式,以便每次使用XML格式时,我都会将该XML传递给该模式,它将自动转换为FLAT文本。以前,开发人员在团队中执行相同的任务,并生成此架构以将XML转换为Flat文件。

<xs:schema xmlns="http://BizTalk_Server_Project1.3_2FlatFileSchema" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://BizTalk_Server_Project1.3_2FlatFileSchema">
    <xs:annotation>
        <xs:appinfo>
            <schemaEditorExtension:schemaInfo xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" />
            <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="LOAN_APPLICATION" />
        </xs:appinfo>
    </xs:annotation>
    <xs:element name="LOAN_APPLICATION">
        <xs:annotation>
            <xs:appinfo>
                <schemaEditorExtension:schemaInfo xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" />
                <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="LOAN_APPLICATION" />
            </xs:appinfo>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:annotation>
                    <xs:appinfo>
                        <groupInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                    </xs:appinfo>
                </xs:annotation>
                <xs:element name="ADDITIONAL_CASE_DATA_x0020_TRANSMITTAL_DATA">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="positional" 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 xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                                </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Header" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="1" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="InvestorInstitutionIdentifier" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="37" sequence_number="2" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="VARIABLE_1">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="positional" 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 xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                                </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Header" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="1" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="Transaction_ID" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="11" sequence_number="2" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="Transaction_Control_Number" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="13" sequence_number="3" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="VARIABLE_2">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="positional" sequence_number="3" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
                        </xs:appinfo>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:annotation>
                                <xs:appinfo>
                                    <groupInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                                </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Header" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="4" sequence_number="1" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="Version_ID" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="5" sequence_number="2" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="Identify_Type_Code" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="2" sequence_number="3" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="Identifier" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="30" sequence_number="4" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="Import_Action_Indicator" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="7" sequence_number="5" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="VARIABLE_3">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="positional" sequence_number="4" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
                        </xs:appinfo>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:annotation>
                                <xs:appinfo>
                                    <groupInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                                </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Variable" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="1" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="File_Type" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="2" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="File_Version_ID" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="9" sequence_number="3" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="MORTGAGE_TERMS">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="positional" sequence_number="5" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
                        </xs:appinfo>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:annotation>
                                <xs:appinfo>
                                    <groupInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                                </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Header" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="1" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="MortgageType" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="82" sequence_number="2" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="AgencyCaseIdentifier" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="45" sequence_number="3" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="BaseLoanAmount" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="15" sequence_number="4" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="RequestedInterestRatePercent" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="7" sequence_number="5" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="LoanAmortizationTermMonths" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="6" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="LoanAmortizationType" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="142" sequence_number="7" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="PROPERTY">
                    <xs:annotation>
                        <xs:appinfo>
                            <b:recordInfo structure="positional" sequence_number="6" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
                        </xs:appinfo>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:annotation>
                                <xs:appinfo>
                                    <groupInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="0" />
                                </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Header" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="1" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="_StreetAddress" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="50" sequence_number="2" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="_City" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="35" sequence_number="3" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="_State" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="3" sequence_number="4" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="_PostalCode" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="8" sequence_number="5" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                            <xs:element name="_FinancedNumberOfUnits" type="xs:string">
                                <xs:annotation>
                                    <xs:appinfo>
                                        <b:fieldInfo justification="left" pos_offset="0" pos_length="84" sequence_number="6" />
                                    </xs:appinfo>
                                </xs:annotation>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

我只需要再次对其进行重新设计。是需要手动手工编写此模式XML还是使用其他工具再次生成此长XML的另一种选择。

xml integration transformation azure-logic-apps flat-file
1个回答
1
投票

使用XSLT进行此转换很容易。但是,对我来说,您所采用的规则并不十分清楚。例如,在标头为02A的行中,我看不到为什么重复字符串“ 123 TBD”,而且根本无法理解空格。

如果您的规则是输出所有文本节点的内容,请使用空格作为2级节点之间的分隔符,并在任何1级节点之前使用换行符(并且不对比其更深的级别的任何文本进行任何准备),你可以做:

<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:for-each select="*/*">
      <xsl:text>&#xa;</xsl:text>
      <xsl:value-of select="*/text()"/>
    </xsl:for-each>
  </xsl:template>
</xsl:transform>

这里的模式不相关。

© www.soinside.com 2019 - 2024. All rights reserved.