将2个单独的XMLType记录合并到一个xml文件中

时间:2016-03-15 08:05:36

标签: xml oracle plsql

我有两个单独的表,其中一个XML Type字段包含需要组合并创建为文件的数据。

表1包含Soap信封消息数据,表2包含SOAP附件正文 - 在本例中为XML格式的发票数据。

使用batch_id,data_id和run_id将表相互链接,以便表1是批处理发票的主数据,其中run_id和data_id充当标识符。表1中的每条记录在详细信息表(表2)中都有一条相关记录

  • 表1:Batch_ID(int),Data_ID(int),Run_ID(int),SOAP_XML(XmlType字段)
  • 表2:Batch_ID(int),Data_ID(int),Run_ID(int),INVOICE_XML(XmlType字段)

我只是想创建一个函数或过程来将这些XMLType数据组合成一个XML文件 - 一个文件包含一个批处理ID的所有记录,所以我需要在两个表中循环每个data_id。

我曾尝试使用XMLConcat,XMLRoot,XMLElement函数,但未设法避免最终XML文件中的额外元素 - 最终结果必须具有与XMLType字段中当前完全相同的数据 - 仅将这两个单独组合记录到一个XML文件(SOAP ENVELOPE + SOAP Attachments)

我想有一个简单的解决方案,但在尝试了不同的解决方案之后,还没有找到任何直接做到这一点的任何建议吗?

表1:XMLType数据示例

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd">
    <SOAP-ENV:Header>
    <eb:MessageHeader xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" SOAP-ENV:mustUnderstand="1" eb:id="xxxxxxxxxxxxxxxxxxxxxxxx">
    <eb:From>
    <eb:PartyId>xxxxxxxxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Sender</eb:Role>
    </eb:From>
    <eb:From>
    <eb:PartyId>xxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Intermediator</eb:Role>
    </eb:From>
    <eb:To>
    <eb:PartyId>xxxxxxxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Receiver</eb:Role>
    </eb:To>
    <eb:To>
    <eb:PartyId>xxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Intermediator</eb:Role>
    </eb:To>
    <eb:CPAId>yoursandmycpa</eb:CPAId>
    <eb:ConversationId>xxxxxxxxxx</eb:ConversationId>
    <eb:Service/>
    <eb:Action/>
    <eb:MessageData>
    <eb:MessageId>xxxxxxx</eb:MessageId>
    <eb:Timestamp>2016-03-01T10:26:04</eb:Timestamp>
    <eb:RefToMessageId/>
    </eb:MessageData>
    </eb:MessageHeader>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <eb:Manifest eb:id="Manifest" eb:version="2.0">
    <eb:Reference eb:id="Invoice" xlink:href="xxxxxx">
    <eb:Schema eb:location="Invoice.xsd" eb:version="1.0"/>
    </eb:Reference>
    </eb:Manifest>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

表2:XMLType示例

<?xml version="1.0" encoding="ISO-8859-15"?>
<?xml-stylesheet type="text/xsl" href="Invoice.xsl"?>
<Invoice Version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Invoice.xsd">
<SellerPartyDetails>
<SellerPartyIdentifier>xxxxxxxxxxxxxxx</SellerPartyIdentifier>
<SellerOrganisationName>xxxxxxxxxxxxxxxxxxxxxxxx</SellerOrganisationName>
<SellerOrganisationTaxCode>xxxxxxxxxxxxx</SellerOrganisationTaxCode>
<SellerPostalAddressDetails>
<SellerStreetName>xxxxxxxxxxxxxxxxxx</SellerStreetName>
<SellerTownName>xxxxxxxxxxxxxxxxxxxxxx</SellerTownName>
<SellerPostCodeIdentifier>xxxxxxxxxxxxxxxxx</SellerPostCodeIdentifier>
</SellerPostalAddressDetails>
</SellerPartyDetails>
</Invoice>

所需的结果数据文件只是表1和表1的组合。 2条记录 - 如下所示:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd">
    <SOAP-ENV:Header>
    <eb:MessageHeader xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" SOAP-ENV:mustUnderstand="1" eb:id="xxxxxxxxxxxxxxxxxxxxxxxx">
    <eb:From>
    <eb:PartyId>xxxxxxxxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Sender</eb:Role>
    </eb:From>
    <eb:From>
    <eb:PartyId>xxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Intermediator</eb:Role>
    </eb:From>
    <eb:To>
    <eb:PartyId>xxxxxxxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Receiver</eb:Role>
    </eb:To>
    <eb:To>
    <eb:PartyId>xxxxxxxxxxxxx</eb:PartyId>
    <eb:Role>Intermediator</eb:Role>
    </eb:To>
    <eb:CPAId>yoursandmycpa</eb:CPAId>
    <eb:ConversationId>xxxxxxxxxx</eb:ConversationId>
    <eb:Service/>
    <eb:Action/>
    <eb:MessageData>
    <eb:MessageId>xxxxxxx</eb:MessageId>
    <eb:Timestamp>2016-03-01T10:26:04</eb:Timestamp>
    <eb:RefToMessageId/>
    </eb:MessageData>
    </eb:MessageHeader>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <eb:Manifest eb:id="Manifest" eb:version="2.0">
    <eb:Reference eb:id="Invoice" xlink:href="xxxxxx">
    <eb:Schema eb:location="Invoice.xsd" eb:version="1.0"/>
    </eb:Reference>
    </eb:Manifest>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
<?xml version="1.0" encoding="ISO-8859-15"?>
    <?xml-stylesheet type="text/xsl" href="Invoice.xsl"?>
    <Invoice Version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Invoice.xsd">
    <SellerPartyDetails>
    <SellerPartyIdentifier>xxxxxxxxxxxxxxx</SellerPartyIdentifier>
  <SellerOrganisationName>xxxxxxxxxxxxxxxxxxxxxxxx</SellerOrganisationName>
    <SellerOrganisationTaxCode>xxxxxxxxxxxxx</SellerOrganisationTaxCode>
    <SellerPostalAddressDetails>
    <SellerStreetName>xxxxxxxxxxxxxxxxxx</SellerStreetName>
    <SellerTownName>xxxxxxxxxxxxxxxxxxxxxx</SellerTownName>
    <SellerPostCodeIdentifier>xxxxxxxxxxxxxxxxx</SellerPostCodeIdentifier>
    </SellerPostalAddressDetails>
    </SellerPartyDetails>
    </Invoice>

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用PL / SQL之类的东西:

 declare
    x varchar(1000);
    begin
    select column1||' '||column2 ... into x 
Where table.id = table2.id

答案 1 :(得分:0)

我设法用一个简单的解决方案来解决这个问题:

PROCEDURE PR_COMPILE_DATA_INTO_FILE(
  P_TARGET_FOLDER IN VARCHAR2,
  P_TARGET_FILENAME IN VARCHAR2,
  P_SOAP_CLOB IN CLOB,
  P_INVOICE_CLOB IN CLOB
  )
AS
  V_TEMP  CLOB;
BEGIN
    dbms_lob.createtemporary(V_TEMP, true);
    dbms_lob.append(V_TEMP, P_SOAP_CLOB);
    dbms_lob.append(V_TEMP,P_INVOICE_CLOB);
    dbms_xslprocessor.clob2file(V_TEMP,P_TARGET_FOLDER,P_TARGET_FILENAME,nls_charset_id('WE8ISO8859P1'));
    dbms_lob.freetemporary(V_TEMP);
END PR_COMPILE_DATA_INTO_FILE;

数据格式正确,xml作为结果文件,一切都已完成。

感谢您对此事的支持和帮助。