I'm trying to build an element type that keep a list of change element type that is the base type of several other child type. I got this code :
<xs:complexType name="change_list" >
<xs:annotation>
<xs:documentation>List of changes.</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded" >
<xs:element name="change" type="aos:change" >
<xs:annotation>
<xs:documentation>Generic or specific type of change.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="activate" type="aos:activate" >
<xs:annotation>
<xs:documentation>Change that will activate an element or do nothing if already activated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="deactivate" type="aos:deactivate" >
<xs:annotation>
<xs:documentation>Change that will deactivate an element or do nothing if already deactivated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="switch" type="aos:switch" >
<xs:annotation>
<xs:documentation>Change that will activate the element if deactivated or deactivate it if activated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="transform" type="aos:transform" >
<xs:annotation>
<xs:documentation>
Change that will modify the geometric state of the element
by applying one or several geometric transformations.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
</xs:sequence>
Im' using CodeSynthesis to generate C++ code.
Now, that seems overkill because here we clearly define access to different types. I think what I want is something simpler like :
List of changes.
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded" >
<xs:element name="change" type="aos:change" >
<xs:annotation>
<xs:documentation>Generic or specific type of change.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
</xs:sequence>
Now that don't allow me to have different tags for different subtypes of changes.
So I thought maybe a good solution might be to use substitution group.
But then I would loose the ability to use the specific sub-type's attributes and elements.
Is the original solution good to do that (having a list of base type object that can get child types too)?
Dont know if you still need an answer... But the following schema does what you need.
First of all the base type and two concrete subtypes (make sure, that your base class has abstract="true" set):
<xs:complexType abstract="true" name="BaseTask">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConcreteTask1">
<xs:complexContent>
<xs:extension base="BaseTask">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ConcreteTask2">
<xs:complexContent>
<xs:extension base="BaseTask">
<xs:sequence>
<xs:element name="Description" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Then adding a list that holds elements that are subtypes of BaseTask:
<xs:element name="TaskList">
<xs:complexType>
<xs:sequence>
<xs:element name="Tasks" minOccurs="0" maxOccurs="unbounded" type="BaseTask" />
</xs:sequence>
</xs:complexType>
</xs:element>
The xml then looks like this:
<TaskList>
<Tasks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ConcreteTask1">
<Name>Foo1</Name>
</Tasks>
<Tasks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ConcreteTask2">
<Name>Foo2</Name>
<Description>Test</Description>
</Tasks>
</TaskList>
What you want is not possible in xml-schema. You can extend (or restrict) a defined type but then this is a new type. Subtyping polymorphism (inclusion polymorphism) doesn't exist in xml-schema.
It sounds like what you want is a list of changes, but you also want the type of change recorded in the list (activate, switch, etc).
What I would do is make a simple element called ChangeType element that would have a "type" attribute whose data type would be another element, ChangeTypeType which would be an enum of your valid changed types. For example:
<element name="ChangeList" type="ChangeListType"/>
<complexType name="ChangeListType">
<annotation>
<documentation>
A list of changes
</documentation>
</annotation>
<sequence>
<element name="change" type="ChangeType" minOccurs="1" maxOccurs="unbounded">
<annotation>
<documentation>
A change event
</documentation>
</annotation>
</element>
</sequence>
</complexType>
<complexType name="ChangeType">
<annotation>
<documentation>
A change unit
</documentation>
</annotation>
<attribute ref="typeOfChange" use="required"/>
</complexType>
<attribute name="typeOfChange" type="ChangeTypeType">
<annotation>
<documentation>
The kind of change
</documentation>
</annotation>
</attribute>
<simpleType name="ChangeTypeType">
<annotation>
<documentation>
Describes the types of allowed changes
</documentation>
</annotation>
<restriction base="token">
<enumeration value="activate"/>
<enumeration value="activate"/>
<enumeration value="switch"/>
<enumeration value="transform"/>
</restriction>
</simpleType>
This would give you an XML document like:
<ChangeList>
<change typeOfChange="activate/>
<change typeOfChange="switch/>
<change typeOfChange="transform/>
</ChangeList>
Related
Here is an example of what I'd like to be able to do as a sample of XML (take note of the file elements):
...
<run-list>
<topic name="topic1"/>
<topic name="topic2">
<file number="2"/>
<file number="3">
/a/b/c /a/b/d /a/b/g/h/i
</file>
</topic>
</run-list>
...
The run-list element can contain any number of topic elements. The topic element may contain zero or more file elements. The file element has the number attribute (required) and may contain zero or more path strings (the list).
I can't figure out how to define a schema type to allow for the definition of the file element as described above. I need the file element to have the number attribute and I'd like to be able to specify an optional list of path values. I have been able to define simple list types for other situations, but they don't have any attributes.
I have been able to do something that is close to this, but needed to define another schema type for the paths and implement it as an element within the file element. So I'd have something like this:
...
<file number="3">
<path>/a/b/c</path>
<path>/a/b/d</path>
<path>/a/b/g/h/i</path>
</file>
...
I'd like to avoid having to define a separate schema type and element to specify the path(s) under a given file element.
Any help would be appreciated.
I think I figured it out. Here's the schema that seems to work:
<xs:complexType name="TestSpecification">
<xs:sequence>
<xs:element name="topic" type="TopicSpecification"
minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="TopicSpecification">
<xs:sequence>
<xs:element name="file" type="FileSpecification" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="FileSpecification">
<xs:simpleContent>
<xs:extension base="EntityPathList">
<xs:attribute name="number" type="xs:positiveInteger" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="EntityPathList">
<xs:list itemType="xs:string" />
</xs:simpleType>
If anyone sees any potential problems with this, suggestions on how to improve or alternatives, please feel free to comment.
Requirement is read data from file and invoke webservice. Target webservice can handle one payload at a time but there will be multiple payload in source.
So am using while loop to process payload one by one.
Issue: In target service EarningTypeInclusion is optional element, so in source some payload this element will be present and in some payload this option element will not be present.
<thresholdRequestInterface xmlns:xs="http://www.sample.com/ns/LMSReferrals">
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
</thresholdRequest>
</thresholdRequestInterface>
If am using assign activity, then selection failure fault will come when optional elements are not present in source payload. We are using BPEL 10g, no option in assign activity to supress selection failure fault.
So decided to use transformation inside while loop .
logic used
Read from file
assign Loop counter=1
Count of payload(read from file)
While loop counter<= Count of payload
pass loop counter param value to transform
transform source i.e thresholdRequest[loopcounter] to target
Invoke target web service
increment loop counter
end loop;
Problem is same data is getting trsnformed.
In the below example, referral 11 data is loading 3 times. I have checked conter value, its getting incremented but inside transformation same values are getting transformed.
<thresholdRequestInterface xmlns:xs="http://www.sample.com/ns/LMSReferrals">
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
<thresholdRequest>
<Referral>12</Referral>
<thresholdValue>100</thresholdValue>
</thresholdRequest>
<thresholdRequest>
<Referral>13</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
</thresholdRequestInterface>
Source
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://www.sample.com/ns/LMSReferrals" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.sample.com/ns/LMSReferrals" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="thresholdRequestInterface">
<xs:complexType>
<xs:sequence>
<xs:element name="thresholdRequest" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Referral" type="xs:string"/>
<xs:element name="thresholdValue" type="xs:int"/>
<xs:element name="EarningTypeInclusion" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="earningType" type="xs:stirng" />
<xs:element name="ProvisionId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please find the schema structure for source and target
Target
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://www.sample.com/ns/LMSReferrals" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.sample.com/ns/LMSReferrals" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="thresholdRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Referral" type="xs:string"/>
<xs:element name="thresholdValue" type="xs:int"/>
<xs:element name="EarningTypeInclusion" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="earningType" type="xs:stirng" />
<xs:element name="ProvisionId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please note schema validation is enabled at target webservice.
Is there a specific reason that you are using Transform.Try using ora:getElement('/thresholdRequestInterface /thresholdRequest',bpws:getVariable(loopCounter))
I'm trying to make an XML Schema - for what's in my opinion a difficult structure. Let's say I have these XML members within a'members'-tag.
<member name="any_name" tab="any_tab" class="any_class">
<summary>Summary</summary>
</member>
and
<member name="any_name" tab="any_tab">
<type class="class_name">
<member name="Name">
<summary>Summary</summary>
</member>
</type>
</member>
Only the name-attribute of a member is required in this context.
I want to be able to validate both of these structures. To do so, I tried to define two complexType's:
<xs:complexType name="normalmember">
<xs:sequence>
<xs:element name="summary" minOccurs="1" />
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="tab" use="optional"/>
<xs:attribute type="xs:string" name="class" use="optional"/>
</xs:complexType>
and
<xs:complexType name="typemember">
<xs:sequence>
<xs:element ref="typememberinfo" />
</xs:sequence>
<xs:attribute type="xs:string" name="class" use="required" />
</xs:complexType>
My problem is that I can't define two 'member' elements with different types in the same scope:
<xs:element name="members">
<xs:complexType>
<xs:sequence>
<xs:element name="member" type="normalmember"></xs:element>
<xs:element name="member" type="typemember"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
How can I make an XML-Schema which is able to validate both structures?
This is not possible this rule is called "Element Declarations Consistent".
The Element Declarations Consistent rule for model groups
(http://www.w3.org/TR/xmlschema-1/#cos-element-consistent) rules out
inconsistent element declarations like the following two conflicting
definitions of element , i.e., cannot be both an "int" and a
"string" in the same group:
(example-1)
<xs:complexType name="example-1">
<xs:sequence>
<xs:element name="a" type="xs:int"/>
<xs:element name="whatever"/>
<xs:element name="a" type="xs:string"/>
</xs:sequence>
</xs:complexType>
I am creating a new web service in which the data format should have to made strict using XMLSchema. But I could not find a way to apply detail xml schema in Coldfusion web service
the web service is passing information as XML and they need to be in a strict format which sould be spedicied in the XML Schema , so that No wrong information is passed.
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UpdatePendingTicketsRequest">
<xs:complexType>
<xs:sequence>
<xs:element ref="SIMS_REPLY_NAVISION_TO_INTOUCH">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UpdatePendingTicketsResponse">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="OK"/>
<xs:enumeration value="ERROR_PROCESSING"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:simpleType name="ST_STATUS">
<xs:restriction base="xs:integer">
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="99"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="TRANSACTIONS">
<xs:complexType>
<xs:sequence>
<xs:element ref="TRANSACTION" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="TRANSACTION">
<xs:complexType>
<xs:sequence>
<xs:element ref="ORIGINAL_TRANSACTION_ID"/>
<xs:element ref="STATUS"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="STATUS">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="ST_STATUS">
<xs:attribute name="description" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="DUPLICATE"/>
<xs:enumeration value="OK"/>
<xs:enumeration value="PROBLEM"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="SIMS_REPLY_NAVISION_TO_INTOUCH">
<xs:complexType>
<xs:sequence>
<xs:element ref="DATETIME"/>
<xs:element ref="TRANSACTIONS"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ORIGINAL_TRANSACTION_ID" type="xs:string"/>
<xs:element name="DATETIME" type="xs:dateTime"/>
<xs:element name="FaultStructure">
<xs:complexType >
<xs:sequence>
<xs:element type="xs:string" name="FaultCode"/>
<xs:element type="xs:string" name="FaultString"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
This is the sample XML Schema which is used to validate the payload. But when i create the same in Coldfusion, this is all i get.
<wsdl:types>
<schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://xml.apache.org/xml-soap"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="CFCInvocationException">
<sequence/>
</complexType>
</schema>
</wsdl:types>
I did a lot of search and never found a concrete solution for it.
This might not be answer but I always recommend that do not build webservice in ColdFusion to receive xml document as arguments. Instead use xml string as argument which later you can convert to xml document using xmlParse(). I had such experience in past and later I need to convert it to xml string argument.
Thanks
Pritesh
I am newbie in xml schema. Is there any possiblility to define that element starts with some characater or symbol. I mean to say, <xs:element minOccurs="1" maxOccurs="1" name="Header">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="1" name="NAME_STUDENTS">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
is there any possible way to define a pattern or tag in xml schema that name of student starts with 'P'??And schema should recognize the text as element NAME_STUDENTS only if the text starts with 'P'
I'm not sure if I fully understand your question but concerning the name element restriction you should look into Xml Schema Regular Expressions.
In your case this would look like this:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Header">
<xs:complexType>
<xs:sequence>
<xs:element name="NAME_STUDENTS" type="filtered-students" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="filtered-students">
<xs:restriction base="xs:string">
<xs:pattern value="^[P]?"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
... but I must confess I'm not really a regex hero so you may want to check the pattern with somebody more proficient.