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
Related
I have the following XSD to validate this XML, but I don't know why it says that is valid. Notice that the pattern only checks for date, not date + time. Do you know how can I put a pattern to take only as valid the date + time? Thank you very much in advance.
XML:
<IN_PARAM>
<DATE_FROM>20/01/2018 10:35:00</DATE_FROM>
<DATE_TO>31/12/2019 18:40:00</DATE_TO>
</IN_PARAM>
XSD:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IN_PARAM">
<xs:complexType>
<xs:sequence>
<xs:element name="DATE_FROM" minOccurs="1" maxOccurs="1" />
<xs:element name="DATE_TO" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DATE_FROM">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DATE_TO">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
I got it. You have to define a type, and that type must have the pattern do you want.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IN_PARAM">
<xs:complexType>
<xs:sequence>
<xs:element name="DATE_FROM" type="DateTimeType" minOccurs="1" maxOccurs="1" />
<xs:element name="DATE_TO" type="DateTimeType" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="DateTimeType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
And of course, if you need it, here is the pattern for dd/MM/yyyy hh:mm:ss:
<xs:pattern value="(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4} (0[0-9]|[1][0-9]|2[1-3]):([0-5][0-9]):([0-5][0-9])"/>
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))
It seems that I am facing some problem while validating this XML
This is XML ,which I have created.
<?xml version="1.0" encoding="UTF-8"?>
<emp_comp xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd">
<emp>
<row_id>0</row_id>
<emp_code>002</emp_code>
<emp_compdt>01-04-2014</emp_compdt>
<emp_cdata>
<emp_cname>Basic</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>100.00</emp_camt>
</emp_cdata>
</emp>
</emp_comp>
Corresponding schema is
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="emp_comp">
<xs:complexType>
<xs:sequence>
<xs:element name="emp" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="row_id" type="xs:int" />
<xs:element name="emp_code" type="xs:string"
minOccurs="0" />
<xs:element name="emp_compdt"
minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
value="|([0-3][0-9][\-](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[\-][0-9]{4})" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="emp_cdata" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="emp_cname"
type="xs:string" minOccurs="0" />
<xs:element name="emp_ccurr"
type="xs:string" minOccurs="0" />
<xs:element name="emp_camt" minOccurs="0" > <!-- ^\d+\.\d{0,2}$ -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+(\.[0-9][0-9]?)?" />
</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>
Error which I am getting is Cannot find the declaration of element 'emp_comp'
what could be the reason for this.
Change:
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
To:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Then, provided that you do really have your XSD at http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd, it will work. Pull it up in a browser to be sure.
Problem
The problem is on first tag, remove this declaration xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd" and and fix <emp_compdt>01-APR-2014</emp_compdt>
Possible Solution
Define a namespace on XSD targetNamespace="http://namespace"
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://namespace">
<xs:element name="emp_comp">
<xs:complexType>
<xs:sequence>
<xs:element name="emp" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="row_id" type="xs:int" />
<xs:element name="emp_code" type="xs:string"
minOccurs="0" />
<xs:element name="emp_compdt"
minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
value="|([0-3][0-9][\-](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[\-][0-9]{4})" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="emp_cdata" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="emp_cname"
type="xs:string" minOccurs="0" />
<xs:element name="emp_ccurr"
type="xs:string" minOccurs="0" />
<xs:element name="emp_camt" minOccurs="0" > <!-- ^\d+\.\d{0,2}$ -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+(\.[0-9][0-9]?)?" />
</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>
the XML could be
<ns1:emp_comp xmlns:ns1="http://namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://namespace http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd">
<emp>
<row_id>0</row_id>
<emp_code>002</emp_code>
<emp_compdt>01-APR-2014</emp_compdt>
<emp_cdata>
<emp_cname>Basic</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>100.00</emp_camt>
</emp_cdata>
</emp>
</ns1:emp_comp>
Ok, this might be first I am answering my own Question
<?xml version="1.0" encoding="UTF-8"?>
<emp_comp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost:9080/ermWeb/XSD/Compensation.xsd">
<emp>
<row_id>0</row_id>
<emp_code>002</emp_code>
<emp_compdt>01-Jan-2014</emp_compdt>
<emp_cdata>
<emp_cname>Basic</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>100.00</emp_camt>
</emp_cdata>
<emp_cdata>
<emp_cname>VPF</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>120.00</emp_camt>
</emp_cdata>
<emp_cdata>
<emp_cname>Employer NPS</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>130.00</emp_camt>
</emp_cdata>
<emp_cdata>
<emp_cname>Employee NPS</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>140.00</emp_camt>
</emp_cdata>
</emp>
</emp_comp>
there were 3 errors as they are pointed out by other answers.
1)01-04-2014 is incorrect, 04 must be replaced by APR
2)xmlns:xsi="http://www.w3.org/2001/XMLSchema" , must add -instance in the end
and
3) I need to use the XSD resource with the nameSpace ,to do that I have to add noNamespace before SchemaLocation in xsi:
Now XML is getting validated in accordance with XSD.
I have an Xsd file
<?xml version="1.0"?>
<xs:schema id="Peoples" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Peoples">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="People">
<xs:complexType>
<xs:all>
<xs:element name="firstname" minOccurs="1" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="lastname" minOccurs="1" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="midinitial" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="email" minOccurs="0" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and the xml file is
<Peoples xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<People>
<firstname>James</firstname>
</People>
</Peoples>
The xml validation it gives
:1:142: cvc-complex-type.2.4.b: The content of element 'People' is not complete. One of '{lastname, midinitial, email}' is expected.
but in this the firstname and lastname is the requied field.
There is a way to validate xml only required field alone
Your problem is not that the validator is validating incorrectly. Your problem is that you don't like its error messages. Your options are to try another validator to see if it produces a validation message for this case that you like better, or to get used to the fact that error messages sometimes don't tell us what we wish they did, and sometimes tell us things we wish they didn't.
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.