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>
Related
I wrote a number of assertions to compare pairs of dates in XSD 1.1 but none of them work.
Examples:
INPUT
<Records content-date="2006-05-04T18:13:51.0Z">
<Record issuance-date="2006-05-04T18:13:51.0Z"
last-update-date="2006-05-04T18:13:51.0Z"
last-renewal-date="2006-05-04T18:13:51.0Z" >
</Record>
<Record issuance-date="2006-05-04T18:13:51.0Z"
last-update-date="2006-05-04T18:13:51.0Z" last-renewal-date="2006-05-04T18:13:51.0Z">
<Event event-date="2006-05-04T18:13:51.0Z" event-type="INITIAL_REGISTRATION">
</Event>
</Record>
</Records>
XSD 1.1 asserts:
<xs:assert id="plausibility-issuance-date-plausibility"
test="#issuance-date < ./#content-date"/>
and
<xs:assert id="plausibility-file-and-record-timezones"
test="timezone-from-dateTime(Record/#issuance-date) = timezone-from-dateTime(REcords#content-date)"/>
Having read up on dateTime and timezone representations I'm a little overwhelmed.
Can anyone please tell me:
where are the errors (I hope it's clear what I'm trying to compare)?
is there a set of simple examples of this kind that make it easier to follow?
Your xs:assert XPATH its not correct because it is assumming that issuance-date and content-date are attributes of the same element, but they are not.
You can use an assert with this sample XPATH to say that "there is no Record with issuance-date greater or equal than its parent content-date":
empty(Record[#issuance-date ge ../#content-date])
Example XSD:
<xs:element name="Records">
<xs:complexType>
<xs:sequence>
<xs:element name="Record" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="issuance-date" type="xs:dateTime"/>
<xs:attribute name="last-update-date" type="xs:dateTime"/>
<xs:attribute name="last-renewal-date" type="xs:dateTime"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="content-date" type="xs:dateTime"/>
<xs:assert id="plausibility-issuance-date-plausibility" test="empty(Record[#issuance-date ge ../#content-date])"/>
</xs:complexType>
</xs:element>
Can I include scripts in my Bundle.config file, or is it only for style bundles?
<?xml version="1.0" encoding="utf-8" ?>
<bundles version="1.0">
<styleBundle path="~/Content/css">
...
</styleBundle>
<scriptBundle path="~/Scripts">
Is this possible?
</scriptBundle>
</bundles>
Also can anyone provide a link to a Bundle.config reference that explains the possible tags and structure? I've searched but all I can come up with is the BundleConfig.cs code way of bundling rather than the markup. I realise why - the markup way is older and maybe even deprecated. But I would like to learn the markup way as its common I will be working with legacy systems that use the older method.
This is called a "bundle manifest". This is an XML file located at ~/bundle.config and loaded through BundleManifest.ReadBundleManifest(); in your Application_Start.
There is an XSD in CodePlex, named BundleManifestSchema.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="BundleConfig" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="include">
<xs:attribute name="path" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="styleBundle">
<xs:sequence>
<xs:element name="include" type="include" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="path" type="xs:string" use="required" />
<xs:attribute name="cdnPath" type="xs:string" use="optional" />
</xs:complexType>
<xs:complexType name="scriptBundle">
<xs:sequence>
<xs:element name="include" type="include" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="path" type="xs:string" use="required" />
<xs:attribute name="cdnPath" type="xs:string" use="optional" />
<xs:attribute name="cdnFallbackExpression" type="xs:string" use="optional" />
</xs:complexType>
<xs:element name="bundles">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element type="styleBundle" name="styleBundle" />
<xs:element type="scriptBundle" name="scriptBundle" />
</xs:choice>
<xs:attribute name="version" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
So yes, scriptBundle is supported.
I don't think it's possible and I think you should really avoid using the XML notation. There are almost no resources regarding that topic on the web. So it might be faster to just rewrite the XML to C#. However, there is a NuGet package that will allow you to configure it via XML. The example can be found on GitHub and on the project site.
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
I have a very strange behaviour in the Show Promotions Dialog in BizTalk 2006. It allows me to promote property fields:
But distinguished fields are disabled:
Any thoughts?
This is the XML Schema generated by the SQL Transport Schema Generation Wizard:
<?xml version="1.0" encoding="utf-16" ?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://ExecutionPlanner.InitializeStep" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://ExecutionPlanner.InitializeStep" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<msbtssql:sqlScript value="exec [InitizializeStep] #ORCHESTRATION_NAME=" ", #PROVIDER_NAME=" ", #STEP_NAME=" "" xmlns:msbtssql="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Step">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="OrchestrationID" type="OrchestrationIDType" />
<xs:element name="Message" type="MessageType" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="OrchestrationIDType">
<xs:simpleContent>
<xs:extension base="xs:string" />
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="MessageType">
<xs:simpleContent>
<xs:extension base="xs:string" />
</xs:simpleContent>
</xs:complexType>
</xs:schema>
Edit your schema to change the OrchestrationID field from a Record to a Field Element. Only Elements and Attributes can be distinguished.
This usually entails deleting the existing Record element, then re-creating an Element with the same name, as Visual Studio wont allow changing an xml node's type. However, you can get around this by opening the xsd file using the XML (Text) Editor using the 'Open With...' option.
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!