I need a sample XSD to support multiple email recipients in a new element. I require each recipient email address in a different element. Can anyone help me with explanation?
Example:
<EmailReceipts>
<address1></address1>
<address2></address2>
</EmailReceipts>
First off, I'd recommend not embedding an index number in the address elements:
<EmailReceipts>
<address>john#example.com</address>
<address>mary#example.org</address>
</EmailReceipts>
Then this XSD will validate the above XML (as well as other XML documents with additional address elements):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EmailReceipts">
<xs:complexType>
<xs:sequence>
<xs:element name="address" maxOccurs="unbounded" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The above XSD will allow any string contents for the address elements. If you've like to be more strict, you could use a regular expression to limit the values for address:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EmailReceipts">
<xs:complexType>
<xs:sequence>
<xs:element name="address" maxOccurs="unbounded" type="EmailAddressType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="EmailAddressType">
<xs:restriction base="xs:string">
<xs:pattern value="([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*#([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Note that the above regular expression is one of many possible, each having various degrees of generality and specificity over a syntax that is more involved than you might imagine.
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])"/>
We have a requirement to allow all the characters (including special chars) except #, $ and space to an XSD element.
I’ve tried the regex as [^$#\s]* but didn’t work. Can you please help with the resolution as I'm not able to figure out.
I tried your regex in a XSD and it works as expected.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.SO53903548" targetNamespace="http://Scratch.SO53903548" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="SpecialString2">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[^$#\s]*" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Will quite happily validate the below, but fail on $,# or space
<ns0:Root xmlns:ns0="http://Scratch.SO53903548">
<SpecialString2>thequickbrownfoxjumpedoverthelazydog#THEQUICKBROWNFOXJUMPEDOVERTHELAZYDOG!~`#%^&*()-_+=</SpecialString2>
</ns0:Root>
I have to generate separate wsdl for separate client.
entry.xsd -> entry.wsdl
migration.xsd -> migration.wsdl
I am using spring boot contract frist approach for generating wsdl from xsd definition. Problem is type are same for both xsd fiels like: credential, so I want to create a common xsd file and include/import in both xsd so can reduce redundant code.
like common.xsd -> entry.xsd, migration.xsd
but getting exception or soap client giving invalid error message.
Any help, how to generate wsdl from two xsd where one is base xsd file?
It's giving, failed to update interface. InvalidFormatException from SOAP Client.
entry.sxd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.test.com/idms-ws"
targetNamespace="http://www.test.com/idms-ws"
elementFormDefault="qualified">
<xs:include schemaLocation="common-element.xsd"></xs:include>
<xs:element name="updateMigrationStatusRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="credential" type="tns:credential" minOccurs="0"/>
<xs:element name="referenceNo" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
common-element.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="credential">
<xs:sequence>
<xs:element name="loginName" type="xs:string" minOccurs="0"/>
<xs:element name="password" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
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 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.