简体   繁体   中英

How to map list of attributes to column-based schema with condition in BizTalk?

I have two schema one is for input xml file and second is for database table.

Please look below for source data of above schema:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl'?> 
<List>
 <Classification domain="Type">deviceSku</Classification>
 <Classification domain="Color">(PRODUCT)RED</Classification>
 <Classification domain="ColorCode">#D82E2E</Classification>
 <Classification domain="OS">Apple iOS</Classification>
 <Classification domain="ChargeType">One Time Charge</Classification>
 <Classification domain="Capacity">128GB</Classification>
</List>

Above file is input xml file which is in list form.

Please look below for table creation scripts which is output, and it is based on column format.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[cata_class](
    [ID] [int] IDENTITY(1000,1) NOT NULL,
    [classification_type] [varchar](100) NULL,
    [classification_color] [varchar](100) NULL,
    [classification_colorCode] [varchar](50) NULL,
    [classification_os] [varchar](100) NULL,
    [classification_chargetype] [varchar](100) NULL,
    [classification_capacity] [varchar](100) NULL,  
PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) 
GO

在此处输入图像描述

As per above SS. I want to add classification value based on condition of domain in destination schema so which functiod is better option and how to use that function?

Please look below for input schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="List">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="Classification">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="domain" type="xs:string" use="required" />
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema> 

Please look below for output schema:

 <?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:ns3="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <fileNameHint xmlns="http://schemas.microsoft.com/servicemodel/adapters/metadata/xsd">Table.dbo</fileNameHint>
    </xs:appinfo>
  </xs:annotation>
  <xs:complexType name="cata_class">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="ID" nillable="true" type="xs:int" />
      <xs:element minOccurs="0" maxOccurs="1" name="classification_type" nillable="true">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="100" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="classification_color" nillable="true">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="100" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="classification_colorCode" nillable="true">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="50" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="classification_os" nillable="true">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="100" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="classification_chargetype" nillable="true">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="100" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element minOccurs="0" maxOccurs="1" name="classification_capacity" nillable="true">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="100" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:element name="cata_class" nillable="true" type="ns3:cata_class" />
  <xs:complexType name="ArrayOfcata_class">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="cata_class" type="ns3:cata_class" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="ArrayOfcata_class" nillable="true" type="ns3:ArrayOfcata_class" />
</xs:schema>

We need to use Equal and Value mapping (flattering) function as per below SS:

在此处输入图像描述

On equal functiod we need to pass domain to check condition as below:

在此处输入图像描述

and in value mapping (flattering) functiod we need to pass equal functiod value as first input and classification node as second input and map it to destination schema node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM