BizTalk 2010 Map destination message show all nodes - biztalk

I have a source schema with less elements than the destination schema. When I run the map only mapped elements in destination schema shows up. I want all the elements in destination schema to show up, even they are empty. How to do this?

Set the "Default Value" of the output schema. This will create empty nodes.

The most convenient way is to use Inline C# Scripting functoid for this.
Scripting functoid:
public string GetEmptyString()
{
return System.String.Empty;
}
You can just link this functoid to all output nodes where you wish to see empty node.
Example:
Input schema:
<xs:schema xmlns="http://person" targetNamespace="http://person" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Surname" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Output schema:
<xs:schema xmlns="http://employee"
targetNamespace="http://employee"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string" />
<xs:element name="MidName" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
<xs:element name="Age" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Input message:
<ns0:Person xmlns:ns0="http://person">
<Name>John</Name>
<Surname>Snow</Surname>
</ns0:Person>
Expected output message:
<ns0:Employee xmlns:ns0="http://employee">
<FirstName>John</FirstName>
<MidName />
<LastName>Snow</LastName>
<Age />
</ns0:Employee>
Solution:
Link Person.Name to Employee.FirstName
Link Person.Surname to Employee.LastName
Create Scripting functoid that returns empty string
Link Scripting functoid to Employee.MidName
Link Scripting functoid to Employee.Age

Related

Resolve collision in class names when converting from WSDL to Java

I am converting WSDL to Java with CXF. When -autoNameResolution key is enabled CXF generates many files with the same content. Is there any way to avoid it?
To avoid nested static classes I've enabled <jaxb:globalBindings localScoping="toplevel">. As you can see in the WSDL element "Apple" is referenced three times. Unfortunately I cannot change WSDL. CXF creates
Apple.java, Apple2.java, Apple3.java accordingly or crashes when -autoNameResolution flag is not set.
<xs:element name="Forest">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="99" minOccurs="0" name="Apple">
<xs:complexType>
<xs:sequence>
<xs:element name="Size" type="xsd:string" />
<xs:element name="Color" type="xsd:string" />
<xs:element name="Taste" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="TreeOne">
<xs:complexType>
<xs:sequence>
<xs:element name="Branch1" type="xsd:string">
</xs:element>
<xs:element maxOccurs="99" minOccurs="0" name="Apple">
<xs:complexType>
<xs:sequence>
<xs:element name="Size" type="xsd:string" />
<xs:element name="Color" type="xsd:string" />
<xs:element name="Taste" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="TreeTwo">
<xs:complexType>
<xs:sequence>
<xs:element name="BranchTwo" type="xsd:string">
</xs:element>
<xs:element maxOccurs="99" minOccurs="0" name="Apple">
<xs:complexType>
<xs:sequence>
<xs:element name="Size" type="xsd:string" />
<xs:element name="Color" type="xsd:string" />
<xs:element name="Taste" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Is there any way to teach wsdl2java not to create Apple2.java and Apple3.java and refer to Apple.java in all three cases? With bindings I could change the name to something else like Apple2->Peach, Apple3->Watermelon but this is not that What I am looking for. It might be obvious to see that all three apples have same set of fields, and are actually the same?
Is there any way to solve that? May be some refactoring plugin that refactors code generated by cxf?
You can force JAXB/XJC to reuse existing classes using the jaxb:class/#ref customization. Something along the lines:
<jaxb:class ref="com.acme.foo.Apple"/>
Where com.acme.foo.Apple is the FQCN of one of the generated Apple classes.
Bind this to the other two xs:complexTypes and JAXB will reuse the existing class instead of generating the same thing again.
I don't have much experience with customizing WSDLs so unfortunatelly I can't point you to the exact syntax of the binding in this case.

How to declare optional date field in XSD

I was using XSD to validate my incoming XML elements.
XSD File
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.rg/2001/XMLSchema"
xmlns:tns="http://xxxy/ervices/V0"
targetNamespace="http://xxxy/ervices/V" elementFormDefault="qualified"
attributeFormDefault="unqualified" >
<xs:complexType name="FailType">
<xs:sequence>
<xs:element name="ConDt" type="xs:date" minOccurs="0" maxOccurs="1" nillable="true"/>
<xs:element name="PreEn" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
My XML File
<Pat xmlns="http://xxxy/ervices/V">
<ConDt></ConDt>
</Pat>
I was getting element is invalid - The value '' is invalid according to its datatype 'http://org/2001/XMLSchema:date' - The string '' is not a valid Date value.
Specifying nillable="true" allows your instance to contain
<ConDt xsi:nil="true"></ConDt>
but it doesn't allow you to write
<ConDt></ConDt>
(Please don't ask me what they were thinking...)
If you want to allow
<ConDt></ConDt>
Then two possible approaches are
define it as a union type that allows either an xs:date or a
zero-length string, or
(my preferred approach) define it as a list type: a list of xs:date values with maxLength="1".
Thanks a lot Michael. I really appreciate your help.
Below code will allow us to declare optional date field.
<xs:element name="ConDt" maxOccurs="unbounded" minOccurs="0">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0" />
<xs:maxLength value="0" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:date" />
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>

Mass Changing Image in Crystal Reports

I want to change an image in about 110 CR 2008 Reports.
I've seen answer about mass changing fields, but I need to change image.
Is their any script or method I could use ?
if you are saving the image in the database you can create schema xml file to reade from the image from DB and call this schema as subreport in the report itself.
the schema will be like this:
You have to make some modification on the id, target, element(table Name) and source as your requirements.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="rptAppSettings" targetNamespace="http://tempuri.org/AppSettings.xsd" xmlns:mstns="http://tempuri.org/AppSettings.xsd" xmlns="http://tempuri.org /AppSettings.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas- microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft- com:xml-msdatasource">
<Connections>
<Connection AppSettingsObjectName="Web.config" AppSettingsPropertyName="ConnectionString" IsAppSettingsProperty="true" Modifier="Assembly" Name="ConnectionString (Web.config)" ParameterPrefix="#" PropertyReference="AppConfig.System.Configuration.ConfigurationManager.0.ConnectionStrings.ConnectionString.ConnectionString" Provider="System.Data.SqlClient" />
</Connections>
<Tables />
<Sources />
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="rptAppSettings" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_DataSetName="rptAppSettings" msprop:Generator_UserDSName="rptAppSettings">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="App_Settings" msprop:Generator_UserTableName="App_Settings" msprop:Generator_RowEvArgName="App_SettingsRowChangeEvent" msprop:Generator_TableVarName="tableApp_Settings" msprop:Generator_TablePropName="App_Settings" msprop:Generator_RowDeletingName="App_SettingsRowDeleting" msprop:Generator_RowChangingName="App_SettingsRowChanging" msprop:Generator_RowDeletedName="App_SettingsRowDeleted" msprop:Generator_TableClassName="App_SettingsDataTable" msprop:Generator_RowChangedName="App_SettingsRowChanged" msprop:Generator_RowEvHandlerName="App_SettingsRowChangeEventHandler" msprop:Generator_RowClassName="App_SettingsRow">
<xs:complexType>
<xs:sequence>
<xs:element name="LogoImage" msprop:Generator_ColumnVarNameInTable="columnLogoImage" msprop:Generator_ColumnPropNameInRow="LogoImage" msprop:Generator_ColumnPropNameInTable="LogoImageColumn" msprop:Generator_UserColumnName="LogoImage" type="xs:base64Binary" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Failed to enable constraints - Do I need to Compile? .Net

Very new to .Net. Everything was working fine until I added <Tracking> to my XML file:
<Product>
<id>product1</id>
<Name>Product 1</Name>
<Packart>detailimg</Packart>
<TitleFile>detailtitleoriginal</TitleFile>
<Description>Description</Description>
<Ingredients>Ingredients</Ingredients>
<FeedingInstructions>Instructions</FeedingInstructions>
<Analysis>Analysis</Analysis>
<Footer>Footer</Footer>
**<Tracking>Test</Tracking>**
</Product>
My XSD file is such:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Products">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string" />
<xs:element name="Name" type="xs:string" />
<xs:element name="Packart" type="xs:string" />
<xs:element name="TitleFile" type="xs:string" />
<xs:element name="Description" type="xs:string" />
<xs:element name="Ingredients" type="xs:string" />
<xs:element name="FeedingInstructions" type="xs:string" />
<xs:element name="Analysis" type="xs:string" />
<xs:element name="Footer" type="xs:string" />
<xs:element name="Tracking" type="xs:string" /></xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then in my aspx page I added:
<%=row[ "Tracking"]%>
When I view the page in a browser I get the error:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Source Error:
Line 19: ds = new System.Data.DataSet();
Line 20: ds.ReadXmlSchema(MapPath("Content/xml/Products.xsd"));
Line 21: ds.ReadXml(MapPath("Content/xml/Products.xml"));
Line 22: Cache.Insert("Products", ds, new System.Web.Caching.CacheDependency(MapPath("Content/xml/Products.xml")),
Line 23: DateTime.Now.AddHours(12), System.Web.Caching.Cache.NoSlidingExpiration);
Source File: d:\ProductDetails.aspx.cs Line: 21
One way to overcome this issue quickly is to disable EnforceConstraints on the dataset:
ds.EnforceConstraints = false;
//now you can load the data
UPDATE: This may have unwanted repercussions, obviously. You should decide whether this is the case or not in your scenario.

Mapping collection as a string to a target node

I am using biztalk 2009 and need help with mapping. I have input like:
<root>
<shop>
<product>
<type>1</type>
<code>ab</code>
<desc></desc>
</product>
<product>
<type>2</type>
<code>cd</code>
<desc></desc>
</product>
</shop>
<address />
<names />
</root>
I want to map the collection of products to a target element as a string of xml that looks like this:
<products><product type="1" code="ab" /><product type="2" code="cd" /></products>
I have found a solution using custom xslt but I dont want to use it as we have found it to be very fickle. Is there any functoids that could do this for me with some custom scripting? I am also a c sharp dev thanks!
This is completely doable out of the box with a simple map.
Here is the soure XML file:
<root>
<shop>
<product>
<type>1</type>
<code>ab</code>
<desc></desc>
</product>
<product>
<type>2</type>
<code>cd</code>
<desc></desc>
</product>
</shop>
<address />
<names />
</root>
Here is the source schema:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="shop">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="product">
<xs:complexType>
<xs:sequence>
<xs:element name="type" type="xs:string" />
<xs:element name="code" type="xs:string" />
<xs:element name="desc" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address">
<xs:complexType />
</xs:element>
<xs:element name="names">
<xs:complexType />
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is the target schema:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="products">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="product">
<xs:complexType mixed="true">
<xs:attribute name="type" type="xs:string" />
<xs:attribute name="code" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And here is the map:
And here is the output:
<products>
<product type="1" code="ab" />
<product type="2" code="cd" />
</products>
Armed witht his result, you can follow one of two suggestions outlined by Mark Brimble in his blog.
How to copy the entire node to element of string type in a map
I am sorry to say this but when mapping gets too involved and there is no obvious way to do this in the mapper I just fall back on a .net helper method inside assign message which will build the output message.
The helper method can take a biztalk message as an argument of type XLANGMessage and return a type of XMLDocument which will be converted to your target message type, providing the xml inside renders the type correctly.
For example:
public static XmlDocument HelperMethod (XLANGMessage message)
{
var sourceType = (SourceType)message[0].RetrieveAs(typeof(SourceType));
var targetType = new TargetType();
// ... Do target type population and serialization to XmlDocument here
return targetAsXmlDoc;
}
It would be trivial to do this inside .net so just take it into .net and do it. Sorry to all the mapping gurus out there!

Resources