I am using BizTalk 2006 R2 to generate a web reference from a WSDL file.
Comparing the generated XSD to the WSDL, it is apparent that a lot of information has been lost.
Consider the following extract from the WSDL:
<s:element form="unqualified" minOccurs="0" maxOccurs="4" name="Applicant">
<s:complexType>
<s:sequence>
<s:element form="unqualified" minOccurs="1" maxOccurs="1" name="ApplicantIdentifier">
<s:simpleType>
<s:restriction base="s:string" />
</s:simpleType>
</s:element>
<s:element form="unqualified" minOccurs="0" maxOccurs="1" name="Name">
<s:complexType>
<s:sequence>
<s:element form="unqualified" minOccurs="0" maxOccurs="1" name="Title">
<s:simpleType>
<s:restriction base="s:string">
<s:maxLength value="10" />
</s:restriction>
</s:simpleType>
</s:element>
<s:element form="unqualified" minOccurs="0" maxOccurs="1" name="Forename">
<s:simpleType>
<s:restriction base="s:string">
<s:pattern value="[0-9A-Za-z \-]*" />
<s:maxLength value="15" />
<s:minLength value="1" />
</s:restriction>
</s:simpleType>
</s:element>
<!-- more -->
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
The equivalent XSD which BizTalk has generated is:
<xs:element minOccurs="0" maxOccurs="unbounded" form="unqualified" name="Applicant">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="ApplicantIdentifier" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="Name">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="Title" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="Forename" type="xs:string" />
<!-- more -->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
So, the XSD has lost the restriction patterns and has set its own values for minOccurs and maxOccurs.
I need to map from another source to the XSD and I wish to trap data that does not conform to the WSDL at that stage.
Does anyone know why BizTalk has not preserved the restrictions in the XSD; or how I can generate non-lossy XSD?
Unless you're doing schema validation in a BizTalk pipeline, restrictions and maxoccurs > 1 aren't actually going to do anything - they're not used by BizTalk at runtime. I'm guessing this is the reason why the web reference is lossy.
I've personally never liked the 'add web reference' feature, or even the 'add adapter metadata'/WCF. If your wsdl is changing that frequently that manually copying the type definitions into an xsd file is too much work:
a) look at building a simple console app to retrieve the wsdl, extract the type(s) and update the xsd file (kick it off from the External Tools menu in VS), and
b) work out what's going wrong with your development process that requires service contract changes that often!
Have you tried using the WCF adapter rather than the "add web reference" to get this done?
Here is an example...
http://blogs.digitaldeposit.net/SARAVANA/post/2007/05/31/BizTalk-2006-R2-consume-an-ASMX-webservice-using-WCF-BasicHttp-adapter.aspx
Related
I have to create constraints on below xml on basis of its tag value
<struct>
<member>
<name>Identifier</name>
<value><i4>11002</i4></value>
</member>
<member>
<name>StartDate</name>
<value><dateTime.iso8601>20160701T12:00:00+0000</dateTime.iso8601>
</value>
</member>
<member>
<name>Type</name>
<value><i4>0</i4></value>
</member>
</struct>
The xsd format that i have created is like,it is just the short form of code and generated using a tool online.
<xs:element minOccurs="0" name="struct">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="member">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string" />
<xs:element minOccurs="0" name="value">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="string" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
What i need is to put constraint on startDate that it is of correct format.
and identifier is only 5 to 10 digits long.
Your XML design is excessively meta and is thereby frustrating your ability to express constraints on data values using XSD 1.0.
You can do one of the following:
Redesign your XML to use concrete tag names such as Identifier, StartDate etc.
Constrain i4 and dateTime.iso8601 apart from name.
Use XSD 1.1 assertions to enforce checking based upon the value of
name.
Recommend you choose #1.
I am trying to generate java classes from a XSD with a XJB. I am running maven plugin maven-jaxb2-plugin in 0.13.1 version.
I want to replace an element type by an other type.
Here is an extract of my xsd file:
<xs:complexType name="TestType">
<xs:sequence>
<xs:element name="field1" type="xs:date" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Test2Type">
<xs:sequence>
<xs:element name="field2" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
If I want to change field1 from xs:date to something else I have NO error.
Here is an extract from my xjb for this modification:
<bindings node="./xs:complexType[#name='TestType']/xs:sequence/xs:element">
<property>
<baseType>
<javaType name="com.test.WTKTest" parseMethod="com.test.WTKTest.parse" printMethod="com.test.WTKTest.print"/>
</baseType>
</property>
</bindings>
Now if I replace
<xs:element name="field1" type="xs:date" minOccurs="1" maxOccurs="1"/>
by
<xs:element name="field1" type="TestType2" minOccurs="1" maxOccurs="1"/>
and I change my parse and print method accordingly, I obtain this error:
compiler was unable to honor this javaType customization. It is attached to a wrong place, or its inconsistent with other bindings.
I have done some tests and I can change the type of an element iif the initial type is a type from xs namespace else it failed!
Thanks for your help!
I wish to create a repeating same named element with two attributes for which the values of each are tied to each other. i.e.
<anElement id="R1" description="Some definition for R1"/>
<anElement id="R2" description="Some definition for R2"/>
Ideally I would define "groups" of id and description attributes together and reference one of the groups for each instance of anElement element.
<complexType name="RElements">
<choice>
<element name="anElement" type="R1Group"/>
<element name="anElement" type="R2Group"/>
</choice>
</complexType>
<complexType name="RElementsType">
<sequence>
<element ref="RElements" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
</complexType>
But Choice doesn't allow multiples of the same element name. I see discussions about how to have multiple elements of the same name but none allow additional attributes let alone having attributes tied to each other. The only way that I can get close is by having a different named element based on the id. i.e.
<R1 id="R1" description="Some definition for R1"/>
<R2 id="R2" description="Some definition for R2"/>
Any suggestions?
You need to provide more information.
Basically to achieve the XML you have provided a simple schema like this would suffice.
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2015 Developer Bundle Edition 13.0.3.5737 (http://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="RootElement">
<xs:complexType>
<xs:sequence>
<xs:element name="anElement" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="descritpion" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
However you mention that the attribute values id and description are linked, you may be able to constrain these, but you need to provide more info. Also I'm not sure why you are looking at choices? Its difficult to see what your attempting give you only provide snippets of the schema
To include the constraints described in later comments the following schema would allow this, but force a change in the XML structure
<AnElement id="E1"> Exterminator serial <ref id="E1"/> </AnElement>
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2015 Developer Bundle Edition 13.0.0.5686 (http://www.liquid-technologies.com)-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="RootElement">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="AnElement">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="ref" minOccurs="0">
<xs:complexType>
<xs:attribute name="id" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="optional" />
</xs:complexType>
<xs:key name="IDVal">
<xs:selector xpath="." />
<xs:field xpath="#id" />
</xs:key>
<xs:keyref name="IdRef" refer="IDVal">
<xs:selector xpath="ref" />
<xs:field xpath="#id" />
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I am getting validation error in the below xsd .
cos-nonambig: "http://alert.schemas.tr.com/TriggerSynchronizationService/Data/2010-02-08/":resyncRequestID and WC[##any] (or elements from their substitution group) violate
"Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.
I think i did not declare xs:any properly.
<xs:complexType name="GenerationTriggerData">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="resyncRequestID" type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="userID" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="alertID" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="triggerID" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="logicalType" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="version" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="state" type="q1:State_Enum" />
<xs:element minOccurs="0" maxOccurs="1" name="criteria" xmlns:q2="http://expressions.schemas.tfn.thomson.com/2006-09-04/" type="q2:ExpressionRoot" />
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
</xs:sequence>
</xs:complexType>
XSD doesn't allow for ambiguous content. UPA is about the parser being able to figure out where it is relative to the XSD, unambiguously; even look-ahead is not allowed.
Since your xsd:any can be (##)any namespace, then resyncRequestID would match it; in that case, is that the first (optional) one, or the wildcard? Here the content is clearly ambigous and no look-ahead would help.
One way is to have xsd:any definition changed such that it won't match any of the content preceding it. Constraining the namespace is always an easy way to do it.
Alternatively, make the particle right before xsd:any mandatory. This way the reader would know where "the wild" begins...
If that is not an option, introduce a special "marker" tag right before xs:any; it must be mandatory!
The above are typically called "refactoring an XSD" to satisfy XSD's UPA design constraint.
I am just learning XML/XSD and am struggling with the implementation of an XML-schema which models a folder structure.
What I had in mind was defining a complexType for the folder which can have additional folder instances that represent subfolders. Using the xsd schema validator here always returns that the schema is invalid.
I tried defining the complexType up front and then using the ref keyword for subfolders:
<xs:complexType name="tFolder">
<xs:sequence>
<xs:element name="Path" type="tFolderType" msdata:Ordinal="0" />
<xs:element ref="Folder" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="File" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="File_Text" msdata:Ordinal="0">
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Type" type="tFolderType" />
As for the element itself:
<xs:element name="Folder" type="tFolder" />
The error returned by the validator is:
"Cannot resolve the name 'Folder' to a(n) 'element declaration' component."
and the error occurs at the line
<xs:element ref="Folder" minOccurs="0" maxOccurs="unbounded" />
Defining the complexType within the element itself yields the exact same error:
<xs:element name="Folder">
<xs:complexType>
<xs:sequence>
<xs:element name="Path" type="tFolderType" msdata:Ordinal="0" />
<xs:element ref="Folder" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="File" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="File_Text" msdata:Ordinal="0">
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Type" type="tFolderType" />
</xs:complexType>
</xs:element>
What I've read, this kind of recursion should work using ref.
Can anyone tell me what I've done wrong? Maybe the xsd validator is just faulty? If so, does anyone know a better alternative? I've tried using the one from w3.org as well, but it seems to be taken offline...
I think this is the way to do it (don't use ref):
<element name="test" type="tns:TestType"></element>
<complexType name="TestType">
<sequence>
<element name="test" type="tns:TestType"></element>
</sequence>
</complexType>