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

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.

Related

Display XML Schema in SQL Query Result

I'm brand new to SQL and SQL Server Management Studio, so bear with me. Here's a shortened version of my query:
SELECT *
FROM [dbo].[BranchLocations] WHERE NOT (PropertyOwnerType IS NULL)
FOR XML PATH('LocationData'), ROOT('MainRoot')
This gives me exactly what I need except for the schema. I don't want to automatically generate a schema because the service to which I upload the XML data only accepts a specific schema structure, and I would prefer to control it.
My schema looks similar to this:
<xs:schema id="LocationData_ds" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="LocationData_ds" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="LocationData">
<xs:complexType>
<xs:sequence>
<xs:element name="EntityID" type="xs:string" />
<xs:element name="AddressLine" type="xs:string" minOccurs="0" />
<xs:element name="Locality" type="xs:string" minOccurs="0" />
<xs:element name="AdminDistrict" type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:string" minOccurs="0" />
<xs:element name="CountryRegion" type="xs:string" minOccurs="0" />
<xs:element name="Latitude" type="xs:double" minOccurs="0" />
<xs:element name="Longitude" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//LocationData" />
<xs:field xpath="EntityID" />
</xs:unique>
</xs:element>
</xs:schema>
My query returns this:
<MainRoot>
<LocationData>
<EntityID>10010000</EntityID>
<AddressLine>1234 address<\/AddressLine>
<Locality>Converse</Locality>
<AdminDistrict>TX</AdminDistrict>
<PostalCode>12345</PostalCode>
<CountryRegion>US</CountryRegion>
</LocationData>
<LocationData>
<EntityID>70390000</EntityID>
<AddressLine>1234 address<\/AddressLine>
<Locality>Denver</Locality>
<AdminDistrict>CO</AdminDistrict>
<PostalCode>12345</PostalCode>
<CountryRegion>US</CountryRegion>
</LocationData>
...
<MainRoot>
And what I need is this:
(and I need ti include<?xml version="1.0" encoding="utf-8" standalone="yes"?> at the top as well)
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<MainRoot>
<xs:schema id="LocationData_ds" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="LocationData_ds" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="LocationData">
<xs:complexType>
<xs:sequence>
<xs:element name="EntityID" type="xs:string" />
<xs:element name="AddressLine" type="xs:string" minOccurs="0" />
<xs:element name="Locality" type="xs:string" minOccurs="0" />
<xs:element name="AdminDistrict" type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:string" minOccurs="0" />
<xs:element name="CountryRegion" type="xs:string" minOccurs="0" />
<xs:element name="Latitude" type="xs:double" minOccurs="0" />
<xs:element name="Longitude" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//LocationData" />
<xs:field xpath="EntityID" />
</xs:unique>
</xs:element>
</xs:schema>
<LocationData>
<EntityID>10010000</EntityID>
<AddressLine>1234 address<\/AddressLine>
<Locality>Converse</Locality>
<AdminDistrict>TX</AdminDistrict>
<PostalCode>12345</PostalCode>
<CountryRegion>US</CountryRegion>
</LocationData>
<LocationData>
<EntityID>70390000</EntityID>
<AddressLine>1234 address<\/AddressLine>
<Locality>Denver</Locality>
<AdminDistrict>CO</AdminDistrict>
<PostalCode>12345</PostalCode>
<CountryRegion>US</CountryRegion>
</LocationData>
...
<MainRoot>
Looking through the documentation has led me here:
https://learn.microsoft.com/en-us/sql/t-sql/xml/insert-xml-dml?view=sql-server-ver15
It isn't working, but I think I might be on the right track.
These answers only relate to generating a schema:
convert database table into XML schema filehow to create XML schema from an existing database in SQL Server 2008
declare #BranchLocations table
(
EntityId varchar(20),
AddressLine varchar(20),
Locality varchar(20),
AdminDistrict varchar(20),
PostalCode varchar(20),
CountryRegion varchar(20),
PropertyOwnerType varchar(20)
);
insert into #BranchLocations(EntityId, AddressLine, Locality, AdminDistrict, PostalCode, CountryRegion, PropertyOwnerType)
values
('10010000', '1234 address', 'Converse', 'TX', '12345', 'US', 'x'),
('70390000', '1234 address', 'Denver', 'CO', '12345', 'US', 'x');
declare #myschema xml = N'<xs:schema id="LocationData_ds" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="LocationData_ds" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="LocationData">
<xs:complexType>
<xs:sequence>
<xs:element name="EntityID" type="xs:string" />
<xs:element name="AddressLine" type="xs:string" minOccurs="0" />
<xs:element name="Locality" type="xs:string" minOccurs="0" />
<xs:element name="AdminDistrict" type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:string" minOccurs="0" />
<xs:element name="CountryRegion" type="xs:string" minOccurs="0" />
<xs:element name="Latitude" type="xs:double" minOccurs="0" />
<xs:element name="Longitude" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//LocationData" />
<xs:field xpath="EntityID" />
</xs:unique>
</xs:element>
</xs:schema>';
declare #res nvarchar(max);
select #res = N'<?xml version="1.0" encoding="utf-8" standalone="yes"?>' +
(
select *
from
(
select #myschema as '*'
union all
select
(
select *
FROM #BranchLocations
WHERE PropertyOwnerType is not null
FOR XML PATH('LocationData')
)
) as src
for xml path(''), root('Mainroot')
);
--test, show result
select 1 as tag, 0 as parent,
#res+'</foo>' as 'test!1!!xmltext'
for xml explicit;
--or
select #res = null;
declare #myxml xml = ( select *
FROM #BranchLocations
WHERE PropertyOwnerType is not null
and 1=2
FOR XML PATH('LocationData'));
--null result when empty resultset from table
select #res =
N'<?xml version="1.0" encoding="utf-8" standalone="yes"?>'
+(select #myschema,#myxml for xml path(''), root('Mainroot'))
where #myxml is not null;
select #res;
What you are looking for is called an Inline XSD Schema.
Here is BOL link: Generate an Inline XSD Schema
Unfortunately, it is very limited: "...You can specify XMLSCHEMA only in RAW and AUTO mode, not in EXPLICIT mode...". Same with the PATH mode.
Additional limitation is that SQL Server keeps XML as UTF-16, and strips an XML prolog from any XML data type internally.
To achieve what you need everything needs to be done manually, i.e. stitch together a prolog, XML Schema, and actual XML.

Replace values in XML string with less than descriptive path

I have a very large xml field inside of a SQL Database that I have to edit regularly. I wrote the following Query to change that code which was easy following the xml path to get to what needed changed.
However I found more things further down in SQL that needs altered and I can not figure out the xml path to edit to make that change.
I've been utilizing the following Query to change just the username
DECLARE #config_xml2 xml
select #config_xml2 = configuration_xml from tblDatafeed where datafeed_name = 'DatafeedName' update tbldatafeed
set configuration_xml.modify('replace value of (//*:NetworkCredentialWrapper/#UserName)[1] with sql:variable("#LOGIN")') where datafeed_name ='DataFeedName'
Which is used to change the Username in the following:
<Tokens>
<Token name="DataFileDirectoryName" />
<Token name="DataFileName" />
<Token name="DataFileExtension" />
<Token name="LastRunTime" />
<Token name="LastFileProcessed" />
</Tokens>
<Transporter>
<transporters:WebServiceTransportActivity xmlns:transporters="clr-namespace:ArcherTech.DataFeed.Activities.Transporters;assembly=ArcherTech.DataFeed" xmlns:out="clr-namespace:ArcherTech.DataFeed;assembly=ArcherTech.DataFeed" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:compModel="clr-namespace:ArcherTech.DataFeed.ComponentModel;assembly=ArcherTech.DataFeed" xmlns:channel="clr-namespace:ArcherTech.DataFeed.Engine.Channel;assembly=ArcherTech.DataFeed" xmlns:engine="clr-namespace:ArcherTech.DataFeed.Engine;assembly=ArcherTech.DataFeed" xmlns:kernel="clr-namespace:ArcherTech.Kernel.Channel;assembly=ArcherTech.Kernel" xmlns="clr-namespace:ArcherTech.DataFeed;assembly=ArcherTech.DataFeed" xmlns:schema="clr-namespace:System.Xml.Schema;assembly=System.Xml" xmlns:xmlLinq="clr-namespace:System.Xml.Linq;assembly=System.Xml" xmlns:domain="clr-namespace:ArcherTech.Common.Domain;assembly=ArcherTech.Common" xmlns:s="clr-namespace:System;assembly=mscorlib" x:Key="transportActivity" SearchType="ReportId" Uri="Type URL Here" RecordsPerFile="100" ReportID="" UseWindowsAuth="false" IsWindowsAuthSpecific="false" WindowsAuthUserName="" WindowsAuthPassword="" WindowsAuthDomain="" ProxyName="" ProxyPort="" ProxyUsername="" ProxyPassword="" ProxyDomain="" IsProxyActive="False" ProxyOption="None" InstanceName="Type Instance Name Here" TempFileOnSuccessAction="DoNothing" TempFileOnSuccessRenameString="" TempFileOnErrorAction="DoNothing" TempFileOnErrorRenameString="" Transform="{engine:DataFeedBinding Path=Transform}" SessionContext="{engine:DataFeedBinding Path=Session}">
<transporters:ArcherWebServiceTransportActivity.Credentials>
<NetworkCredentialWrapper UserName="" />
</transporters:ArcherWebServiceTransportActivity.Credentials>
</transporters:ArcherWebServiceTransportActivity>
</Transporter>
<Iterator>
<XmlIterator>
But now I need to alter a string that a lot more complex and I am not sure my xml location is right. I have tried using //*NewSourceName1/#Calculation but it doesnt seem work:
Line of code Here I am trying to edit:
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC(&quot;MYSTRINGOFTEXTHERE&quot;)" dfm:SimpleFieldType="StaticText" />
Full xml it falls under
<Action>
<DataTransfer TargetType="Application" TargetLevel="20595ffc-afd5-4d34-babb-c8fa67c610ee" DisableValidation="true" PreValidate="false" InsertRecords="true" UpdateRecords="false" SyncAction="None" SyncFlagField="00000000-0000-0000-0000-000000000000" SyncFlagValue="00000000-0000-0000-0000-000000000000">
<Source>
<Schema><Schemas>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.archer-tech.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dfm="http://schemas.archer-tech.com/2009/xaml/datafeed" xmlns:c="http://archertech.com/ChannelFramework/Extensions" dfm:ComplexFieldType="None">
<xs:element name="ArcherRecords" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="ArcherRecord" nillable="true" c:Name="ArcherRecord" dfm:ComplexFieldType="None" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" nillable="true" c:Name="Name" />
<xs:element name="Container_Type" nillable="true" c:Name="Container_Type">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path" type="xs:string" nillable="true" c:Name="Path" />
<xs:element name="Abbreviation_Unique_Key" type="xs:string" nillable="true" c:Name="Abbreviation_Unique_Key" />
<xs:element name="Container_Owner" nillable="true" c:Name="Container_Owner">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Send_Upstream" nillable="true" c:Name="Send_Upstream">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewSourceName" type="xs:string" nillable="true" c:Name="Iteration" c:Calculation="=IF(AND(HOUR(NOW())&gt;=0,HOUR(NOW())&lt;8), &quot;ONE&quot;,&#xA; IF(AND(HOUR(NOW())&gt;=8,HOUR(NOW())&lt;16), &quot;TWO&quot;, &quot;THREE&quot;))" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC(&quot;MyTextHere&quot;)" dfm:SimpleFieldType="StaticText" />
<xs:element name="NewSourceName2" type="xs:string" nillable="true" c:Name="Date_Created" c:Calculation="=DATEFORMAT(TODAY(), &quot;MM/dd/yyyy&quot;)" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName3" type="xs:string" nillable="true" c:Name="Created_By" c:Calculation="=STATIC(&quot;Local Dashboard&quot;)" dfm:SimpleFieldType="StaticText" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</Schemas></Schema>
</Source>
Hopeful out come (Look for MYSTRINGOFTEXTHERE or if I could just edit all of =STATIC("MYSTRINGOFTEXTHERE")):
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC(&quot;MYSTRINGOFTEXTHERE&quot;)" dfm:SimpleFieldType="StaticText" />
What I tried that didn't work
DECLARE #config_xml2 xml
select #config_xml2 = configuration_xml from tblDatafeed where datafeed_name = 'DatafeedName' update tbldatafeed
set configuration_xml.modify('replace value of (//*:NewSourceName1/#Calculation)[1] with sql:variable("#CoolVariableName")') where datafeed_name ='DataFeedName'
Any help would be greatly appreciated.
The XPath expression was completely off, so I adjusted it.
In XML, there are only five built-in character entities: <, >, &, " and &apos; for <, >, &, " and ' respectively. I replaced them with their literals. Please try the following.
SQL
DECLARE #tbl TABLE (id int IDENTITY PRIMARY KEY, configuration_xml XML);
INSERT INTO #tbl (configuration_xml)
VALUES
(N'<Action>
<DataTransfer TargetType="Application" TargetLevel="20595ffc-afd5-4d34-babb-c8fa67c610ee" DisableValidation="true" PreValidate="false" InsertRecords="true" UpdateRecords="false" SyncAction="None" SyncFlagField="00000000-0000-0000-0000-000000000000" SyncFlagValue="00000000-0000-0000-0000-000000000000">
<Source>
<Schema>
<Schemas>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.archer-tech.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dfm="http://schemas.archer-tech.com/2009/xaml/datafeed" xmlns:c="http://archertech.com/ChannelFramework/Extensions" dfm:ComplexFieldType="None">
<xs:element name="ArcherRecords" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="ArcherRecord" nillable="true" c:Name="ArcherRecord" dfm:ComplexFieldType="None" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" nillable="true" c:Name="Name" />
<xs:element name="Container_Type" nillable="true" c:Name="Container_Type">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path" type="xs:string" nillable="true" c:Name="Path" />
<xs:element name="Abbreviation_Unique_Key" type="xs:string" nillable="true" c:Name="Abbreviation_Unique_Key" />
<xs:element name="Container_Owner" nillable="true" c:Name="Container_Owner">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Send_Upstream" nillable="true" c:Name="Send_Upstream">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewSourceName" type="xs:string" nillable="true" c:Name="Iteration" c:Calculation="=IF(AND(HOUR(NOW())&gt;=0,HOUR(NOW())&lt;8), &quot;ONE&quot;,&#xA; IF(AND(HOUR(NOW())&gt;=8,HOUR(NOW())&lt;16), &quot;TWO&quot;, &quot;THREE&quot;))" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC(&quot;MyTextHere&quot;)" dfm:SimpleFieldType="StaticText" />
<xs:element name="NewSourceName2" type="xs:string" nillable="true" c:Name="Date_Created" c:Calculation="=DATEFORMAT(TODAY(), &quot;MM/dd/yyyy&quot;)" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName3" type="xs:string" nillable="true" c:Name="Created_By" c:Calculation="=STATIC(&quot;Local Dashboard&quot;)" dfm:SimpleFieldType="StaticText" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</Schemas>
</Schema>
</Source>
</DataTransfer>
</Action>');
DECLARE #CoolVariableName varchar(30) = 'Whatever Value';
UPDATE #tbl
SET configuration_xml.modify('replace value of (//xs:element[#name="NewSourceName1"]/#*:Calculation)[1] with sql:variable("#CoolVariableName")');
SELECT * FROM #tbl;

Howto use BizTalk TestableReceivePipeline when having a schema which has an imported schema

Under Microsoft BizTalk 2009, we want to test the ReceivePipeline(which has a Flat file disassembler) with the built-in TestableReceivePipeline class.
It works fine if we use one single Schema, but it throws an error (System.Xml.Schema.XmlSchemaException: The 'ABC' element is not declared.) when we try to use a schema(Schema1) which has an imported schema(Schema2) inside.
Why I'm getting this error?
code for testing pipeline:
StringCollection documents = new StringCollection();
documents.Add(#"c:\Test.dat");
StringCollection parts = new StringCollection();
Dictionary<string, string> schemas = new Dictionary<string, string>();
schemas.Add("MyCompany.Schema2", #"C:\Schema2.xsd");
schemas.Add("MyCompany.Schema1", #"C:\Schema1.xsd");
Microsoft.BizTalk.TestTools.Pipeline.TestableReceivePipeline pipeline = new MyReceivePipeline();
pipeline.TestPipeline(documents, parts, schemas);
Schema1.xsd source:
<xs:import schemaLocation=".\Schema2.xsd" namespace="http://MyCompany.Schema2" />
<xs:element name="Schema1">
<xs:complexType>
<xs:sequence>
<xs:element name="Header">
<xs:complexType>
<xs:sequence>
<xs:element name="ClientRef" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="1" wrap_char_type="default" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="ns1:Data" />
<xs:element name="Tail">
<xs:complexType>
<xs:sequence>
<xs:element name="RecordCount" type="xs:int">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="3" wrap_char_type="default" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Schema2.xsd source:
<xs:element name="Data">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string" nillable="true">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" wrap_char_type="default" sequence_number="2" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Surname" type="xs:string" nillable="true">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="3" wrap_char_type="default" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
AFAIK this is currently not supported in BizTalk 2009.

Can we add new attribute or change type of existing attribute to a "Referenced Element"?

In my XML schema I have an element being referenced tens of times by other elements but with different enumerated values for one of its attribute.
For now, instead of creating this element in global space and referencing it later, I am creating a new instance wherever it is needed. This approach has increased my schema size enormously because of repeated creation of almost same element many times. It also may have adverse effect on efficiency of the schema.
The only way that I see is to create element once and then reference it many times but my problem is: one of the attribute of this referenced element is required to have a different set of enumerations for each referencing element.
My question is:
Is it possible to to add an attribute to a "Referenced Element" in XML Schema?
Something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.myDomain.com" xmlns="http://www.myDomain.com" elementFormDefault="qualified">
<xs:simpleType name="myValues1">
<xs:restriction base="xs:string">
<xs:enumeration value="value1" />
<xs:enumeration value="value2" />
</xs:restriction>
</xs:simpleType>
<xs:element name="myElement">
<xs:complexType mixed="true">
<xs:attribute name="attr1" type="xs:string" />
<xs:attribute name="attr2" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="MainElement1">
<xs:complexType>
<xs:sequence>
<xs:element ref="myElement">
<xs:complexType>
<xs:attribute name="myAtt" type="myValues1" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="mainAtt1" />
</xs:complexType>
</xs:element>
</xs:schema>
Or can we change type of an existing attribute of a "Referenced Element" in XML Schema?
something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.myDomain.com" xmlns="http://www.myDomain.com" elementFormDefault="qualified">
<xs:simpleType name="myValues1">
<xs:restriction base="xs:string">
<xs:enumeration value="value1" />
<xs:enumeration value="value2" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="myValues2">
<xs:restriction base="xs:string">
<xs:enumeration value="value3" />
<xs:enumeration value="value4" />
</xs:restriction>
</xs:simpleType>
<xs:element name="myElement">
<xs:complexType mixed="true">
<xs:attribute name="attr1" type="xs:string" />
<xs:attribute name="attr2" type="xs:string" />
<xs:attribute name="myAtt" type="myValues1" />
</xs:complexType>
</xs:element>
<xs:element name="MainElement1">
<xs:complexType>
<xs:sequence>
<xs:element ref="myElement">
<xs:complexType>
<xs:attribute name="myAtt" type="myValues2" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="mainAtt1" />
</xs:complexType>
</xs:element>
</xs:schema>
You cannot override the content model of a referenced element. The point of the reference is that it points to exactly the same element every time.
If you really want the element to have different content, you are better off defining multiple global complex types and using them, rather than using an element reference:
<xs:complexType name="Type1" mixed="true">
<xs:attribute name="attr1" type="xs:string" />
<xs:attribute name="attr2" type="xs:string" />
<xs:attribute name="myAtt" type="myValues1" />
</xs:complexType>
<xs:complexType name="Type2" mixed="true">
<xs:complexContent>
<xs:extension base="Type1">
<xs:attribute name="myAtt2" type="myValues2" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="MainElement1">
<xs:complexType>
<xs:sequence>
<xs:element name="myElement" type="Type1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
I would not worry too much about performance. The reference to the global types will be resolved only once at schema load time.

XML and Sql Server 2005

i have a problem that I want to resolve in a best possible way. The thing is that I made a schema that looks like this:
print("
<xs:complexType name="rentACarT">
<xs:sequence>
<xs:element name="poslovnice" type="poslovniceT" />
<xs:element name="korisnici" type="korisniciT" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="poslovniceT">
<xs:sequence>
<xs:element name="poslovnica" type="poslovnicaT" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="poslovnicaT">
<xs:sequence>
<xs:element name="naziv" type="xs:string" />
<xs:element name="adresa" type="adresaT" />
<xs:element name="grad" type="gradT" />
<xs:element name="vozila" type="vozilaT" />
<xs:element name="zaposlenici" type="zaposleniciT" />
<xs:element name="posudbe" type="posudbeT" />
</xs:sequence>
<xs:attribute name="id" type="xs:int" />
</xs:complexType>
<xs:complexType name="vozilaT">
<xs:sequence>
<xs:element name="vozilo" type="voziloT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="zaposleniciT">
<xs:sequence>
<xs:element name="zaposlenik" type="zaposlenikT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="korisniciT">
<xs:sequence>
<xs:element name="korisnik" type="korisnikT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="posudbeT">
<xs:sequence>
<xs:element name="posudba" type="posudbaT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="posudbaT">
<xs:sequence>
<xs:element name="idVozila" type="xs:int" />
<xs:element name="jmbgZaposlenika" type="jmbgT" />
<xs:element name="jmbgKorisnika" type="jmbgT" />
<xs:element name="datumPosudbe" type="xs:date" />
<xs:element name="ugovoreniDatumPovratka" type="xs:date" />
<xs:element name="stvarniDatumPovratka" type="xs:date" />
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
<xs:complexType name="voziloT">
<xs:sequence>
<xs:element name="registracija" type="xs:string" />
<xs:element name="modelVozila" type="modelVozilaT" />
<xs:element name="godinaProizvodnje" type="godinaT" />
<xs:element name="cijenaPosudbePoDanu" type="xs:double" />
</xs:sequence>
<xs:attribute name="id" type="xs:int" />
</xs:complexType>
<xs:complexType name="zaposlenikT">
<xs:sequence>
<xs:element name="ime" type="xs:string" />
<xs:element name="prezime" type="xs:string" />
<xs:element name="spol" type="spolT" />
<xs:element name="datumZaposlenja" type="xs:date" />
<xs:element name="grad" type="xs:double" />
</xs:sequence>
<xs:attribute name="jmbg" type="jmbgT" />
</xs:complexType>
<xs:complexType name="korisnikT">
<xs:sequence>
<xs:element name="ime" type="xs:string" />
<xs:element name="prezime" type="xs:string" />
<xs:element name="spol" type="spolT" />
<xs:element name="adresa" type="adresaT" />
<xs:element name="grad" type="gradT" />
<xs:element name="status" type="statusKorisnikaT" />
</xs:sequence>
<xs:attribute name="jmbg" type="jmbgT" />
</xs:complexType>
<xs:complexType name="modelVozilaT">
<xs:sequence>
<xs:element name="tipVozila" type="tipVozilaT" />
<xs:element name="marka" type="xs:string" />
<xs:element name="model" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="tipVozilaT">
<xs:restriction base="xs:string">
<xs:enumeration value="auto" />
<xs:enumeration value="kombi" />
<xs:enumeration value="kamion" />
<xs:enumeration value="limuzina" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="godinaT">
<xs:restriction base="xs:int">
<xs:minInclusive value="1980" />
<xs:maxInclusive value="2050" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="jmbgT">
<xs:restriction base="xs:string">
<xs:pattern value="([0-9]){13}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="spolT">
<xs:restriction base="xs:string">
<xs:enumeration value="m" />
<xs:enumeration value="f" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="statusKorisnikaT">
<xs:restriction base="xs:string">
<xs:enumeration value="stalni" />
<xs:enumeration value="novi" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="gradT">
<xs:sequence>
<xs:element name="postanskiBroj" type="xs:int" />
<xs:element name="naziv" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="adresaT">
<xs:sequence>
<xs:element name="ulica" type="xs:string" />
<xs:element name="kucniBroj" type="xs:int" />
</xs:sequence>
</xs:complexType>
");
Now, I don't want to put the entire xml document into one row. At least I think it is bad.
I would like to move "poslovnice"(contains multiple "poslovnica") in one table and "vozila" in other...
And is it better to hold each "poslovnica" in one row in table Poslovnica or have all elements "poslovnica" in one row?
And what about uniqueness since SQL Server doesn't support unique xml data type, I've seen that you can use triggers and functions, is there any other way?
Also, if I break the xml document, and have poslovnice in one table and their vozila in other, how to achieve to show that vozilo belongs to poslovnica, should I put id of poslovnica in each vozilo in xml or should I reference rows in SQL Server?
Or would you reccomend some other database?
Thank you very much, I am sorry if I wasn't clear enough :( !
Miroslav
well first you have to ask yourself why do you want it stored in XML in the db?
this seems like a perfect scenario to have tables Poslovnica, Vozilo and Zaposlenik and have intermediate tables that hold info on which employee rented what car where.
i don't see a reason to store this in xml at all.