You can't put choice tag inside the all tag. So, is there any workaround to get this functionallity?
For example, I have<settings> tag like:
<settings>
<logging />
<sending />
<useonly />
</settings>
Or something like
<settings>
<logging />
<notuseonly />
<sending />
</settings>
So I want to prevent <useonly> and <notuseonly> showing up together, while the order is not important. And if allowed, in XSD it would look like:
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" ref="sending" />
<xs:element minOccurs="0" maxOccurs="1" ref="logging" />
<xs:choice>
<xs:element minOccurs="0" maxOccurs="1" ref ="useonly" />
<xs:element minOccurs="0" maxOccurs="1" ref ="notuseonly" />
</xs:choice>
</xs:all>
Any thoughts?
Check this link: http://www.w3.org/wiki/Needs_choice_inside_all
I summarize for you the solutions proposed:
One solution is to wrap the element that can change inside another:
<xsd:all>
<xsd:element minOccurs="0" maxOccurs="1" ref="sending" />
<xsd:element minOccurs="0" maxOccurs="1" ref="logging"/>
<xsd:element minOccurs="0" maxOccurs="1" ref ="usetype"/>
</xsd:all>
<xsd:element name="usetype">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="useonly"/>
<xsd:element ref="notuseonly"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
The other one is to use a substitution group:
<xsd:all>
<xsd:element ref="sending"/>
<xsd:element ref="logging"/>
<xsd:element ref="usetype"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="usetype" abstract="true"/>
<xsd:element name="useonly" substitutionGroup="usetype"> ... </xsd:element>
<xsd:element name="notuseonly" substitutionGroup="usetype"> ... </xsd:element>
Related
Is it possible to reference an element in xsd, so that its content is written into another?
I think of someting like "shipping address" and "billing address".
If you choose that "billing address" is the same as "shipping address", than take the content of field "shipping address" and write it into "billing address".
I'm new to xsd/xml, so suggestions and criticism are welcome.
This is what I've got so far...
<xsd:group name="c_Shipping_Adress">
<xsd:element name="shipping_address">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title"/>
<xsd:element name="First_Name"/>
<xsd:element name="Last_Name"/>
<xsd:element name="Street"/>
<xsd:element name="Zip"/>
<xsd:element name="City"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:group>
<xsd:group name="c_Billing_Adress">
<xsd:element name="billing_address">
<xsd:complexType>
<xsd:choice>
<xsd:element name="is_same_as_shipping_address">
<xsd:group ref="shipping_address"/>
</xsd:element>
<xsd:group name="is_not_same_as_shipping_address">
<xsd:sequence>
<xsd:element name="Title"/>
<xsd:element name="First_Name"/>
<xsd:element name="Last_Name"/>
<xsd:element name="Street"/>
<xsd:element name="Zip"/>
<xsd:element name="City"/>
</xsd:sequence>
</xsd:group>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:group>
To be honest its not very clear what your asking, and your XSD is not structured correctly, making it difficult to determine your intentions. But hopefully the following will provide enough of a basis to build on.
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2019 BETA (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="ShippingAddress" type="AddressType" />
<xs:element name="BillingAddress" type="AddressType" />
<xs:element name="OtherAddress">
<xs:complexType>
<xs:complexContent>
<xs:extension base="AddressType">
<xs:sequence>
<xs:element name="ExtraThing" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="Title" type="xs:string" />
<xs:element name="First_Name" type="xs:string" />
<xs:element name="Last_Name" type="xs:string" />
<xs:element name="Street" type="xs:string" />
<xs:element name="Zip" type="xs:string" />
<xs:element name="City" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
I've found similar questions but some of the conditions don't apply to my case or the answers do not work.
I created a CXF (3.2.1) SOAP client to consume an external web service so I don't have control over the WSDL and schemas.
The relevant part (not the entire schema) of the service schema is:
<xsd:complexType name="LegalEntityService1">
<xsd:annotation>
<xsd:appinfo source="http://xmlns.oracle.com/adf/svc/metadata/">
<key xmlns="http://xmlns.oracle.com/adf/svc/metadata/">
<attribute>LegalEntityId</attribute>
</key>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element minOccurs="0" name="LegalEntityId" type="xsd:long" sdoXML:dataType="sdoJava:LongObject"/>
<xsd:element minOccurs="0" name="PartyId" type="xsd:long" sdoXML:dataType="sdoJava:LongObject"/>
<xsd:element minOccurs="0" name="LegalEntityIdentifier" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="Name" type="xsd:string"/>
<xsd:element default="1" minOccurs="0" name="GeographyId" type="xsd:long" sdoXML:dataType="sdoJava:LongObject"/>
<xsd:element minOccurs="0" name="TransactingEntityFlag" nillable="true" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="EffectiveFrom" nillable="true" type="ns0:date-Date"/>
<xsd:element minOccurs="0" name="EffectiveTo" nillable="true" type="ns0:date-Date"/>
<xsd:element minOccurs="0" name="ObjectVersionNumber" type="xsd:int" sdoXML:dataType="sdoJava:IntObject"/>
<xsd:element minOccurs="0" name="ActivityCode" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="SubActivityCode" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="TypeOfCompany" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="RegistrationCodeLe" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="RegistrationCodeEtb" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="RegistrationCodeLeValue" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="RegistrationCodeEtbValue" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="JurisdictionName" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="PlaceOfRegistration" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="LegalEmployerFlag" nillable="true" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="ParentPsuId" nillable="true" type="xsd:long"/>
<xsd:element minOccurs="0" name="PsuFlag" nillable="true" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="JurisdictionId" nillable="true" type="xsd:long"/>
<xsd:element minOccurs="0" name="GeographyId1" type="xsd:long" sdoXML:dataType="sdoJava:LongObject"/>
<xsd:element minOccurs="0" name="TerritoryShortName" type="xsd:string"/>
<xsd:element minOccurs="0" name="TerritoryCode" type="xsd:string"/>
<xsd:element minOccurs="0" name="Country" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="LegalAddress" type="xsd:string"/>
<xsd:element minOccurs="0" name="Name1" type="xsd:string"/>
<xsd:element minOccurs="0" name="LegalEntityId1" type="xsd:long" sdoXML:dataType="sdoJava:LongObject"/>
I'm specifically having problems with:
<xsd:element minOccurs="0" name="LegalEntityId1" type="xsd:long" sdoXML:dataType="sdoJava:LongObject"/>
It is minOccurs=0 so it should allow an empty tag but when it unmarshalles the following response it fails with javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: For input string: "".
The annotation seems correct as it is required=false.
#XmlElementRef(name = "LegalEntityId1", namespace = "http://xmlns.oracle.com/apps/financials/legalEntity/legalEntities/legalEntityService/", type = JAXBElement.class, required = false)
protected JAXBElement<Long> legalEntityId1;
I don't understand why it is failing. I know the problem is LegalEntityId1 because I checked it with the debugger.
EDIT #1
Here is the entire stacktrace https://pastebin.com/jS9Pu4rB.
This issue was due to the type of the element.
<LegalEntityId1></LegalEntityId1> this is not a Long format because it is parsed as "" empty string.
if you need instead a "null" meaning, that in xml is "nil" you should change your xsd in <xsd:element minOccurs="0" name="LegalEntityId1" type="xsd:long" nillable="true" /> that in xml will be <LegalEntityId1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> .
Can you have an allready restricted type and then derive from this type by extension and add elements that do not fit to a base type?
<xsd:complexType name="absHcontainerType">
<xsd:complexContent>
<xsd:restriction base="e:urContentType">
<xsd:sequence>
<xsd:element ref="e:absMcontainer" minOccurs="0"
maxOccurs="1" />
<xsd:element ref="e:absHtitle" minOccurs="1" maxOccurs="unbounded" />
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element ref="e:absMcontainer" />
<xsd:element ref="e:absHcontainer" />
<xsd:element ref="e:absContainer" />
</xsd:choice>
</xsd:sequence>
<xsd:attributeGroup ref="e:typehcontainer" />
<xsd:attributeGroup ref="e:anyattr" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
And then derive this like this:
<xsd:complexType name="absHcontainerType2">
<xsd:complexContent>
<xsd:extension base="absHcontainerType">
<xs:sequence>
<xs:element name="xy" type="xs:string"/>
<xs:element name="xyz" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xsd:complexContent>
</xsd:complexType>
As long as you don't put back things that got restricted away, I wouldn't expect a problem. Are you in fact getting an error when you try it?
I have a form that I am defining in my Xquery request. This form is built on an XSD schema.
My form:
<xsd:element name="AddInsuranceToOrderForm">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OrderId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="DistributionChannel" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="FloatNumber" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="UserId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="SalesId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="TotalDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
<xsd:element name="ChangeDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
**<xsd:element ref="tns:tenderItem" minOccurs="0" maxOccurs="unbounded"/>**
<xsd:element name="ProtectionPlans" type="tns:ProtectionPlanItemType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="InsurancePlans" type="tns:FeatureItemType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Notice tenderItems is a ref. It's source is here:
<xsd:element abstract="true" name="tenderItem" type="tns:TenderType"/>
<xsd:complexType name="TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="date" type="xsd:dateTime"/>
<xsd:element maxOccurs="1" minOccurs="0" name="lineNumber" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="tenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="returnTenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="tenderType" type="tns:TenderTypeType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="amount" type="xsd:decimal"/>
<xsd:element maxOccurs="1" minOccurs="0" name="signature" type="tns:SignatureType"/>
</xsd:sequence>
</xsd:complexType>
There are several specific tenders that extend tenderType that I want to add to my Xquery request. Here is an example:
<xsd:element name="billToAccount" substitutionGroup="tns:tenderItem" type="tns:BillToAccountType"/>
<xsd:complexType name="BillToAccountType">
<xsd:complexContent>
<xsd:extension base="tns:TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="accountId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="subscriptionId" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="chargeDescription" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="lineItems" type="tns:BillToAccountLineItemType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
So how is this done in Xquery? I've tried the following:
{
for $BillToAccount in $addInsuranceToOrderABM1/ns3:MessagePayload/ns3:AddInsuranceToOrder/ns1:AddInsuranceToOrderDataArea/ns2:TenderItem
return
<ns2:billToAccount>
{
for $Date in $BillToAccount/ns0:Date
return
<ns2:date>{ data($Date) }</ns2:date>
}…
}
I did this for each tenderType, but the XML elements are not supported by the mapper.
You can use schema-element(ns3:tenderItem) to match any element in that substitution-group.
import schema default element namespace "http://www.example.com/xml-namespace/" at "schema.xsd";
declare variable $input as schema-element(AddInsuranceToOrderForm)
:= validate { doc('data.xml')/AddInsuranceToOrderForm };
for $item in $input/schema-element(tenderItem)
return $item
With schema.xsd as:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:tns="http://www.example.com/xml-namespace/"
targetNamespace="http://www.example.com/xml-namespace/">
<xsd:element name="AddInsuranceToOrderForm">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OrderId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="DistributionChannel" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="FloatNumber" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="UserId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="SalesId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="TotalDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
<xsd:element name="ChangeDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="tns:tenderItem" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element abstract="true" name="tenderItem" type="tns:TenderType"/>
<xsd:complexType name="TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="date" type="xsd:dateTime"/>
<xsd:element maxOccurs="1" minOccurs="0" name="lineNumber" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="tenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="returnTenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="amount" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="BillToAccount" substitutionGroup="tns:tenderItem" type="tns:BillToAccountType"/>
<xsd:complexType name="BillToAccountType">
<xsd:complexContent>
<xsd:extension base="tns:TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="accountId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="subscriptionId" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="chargeDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
And data.xml as:
<?xml version="1.0" encoding="UTF-8"?>
<AddInsuranceToOrderForm xmlns="http://www.example.com/xml-namespace/">
<OrderId>1</OrderId>
<DistributionChannel>1</DistributionChannel>
<FloatNumber>1</FloatNumber>
<UserId>1</UserId>
<SalesId>1</SalesId>
<TotalDue>1</TotalDue>
<ChangeDue>1</ChangeDue>
<BillToAccount>
<date>2012-10-01T23:59:59</date>
<lineNumber>line 1</lineNumber>
<tenderId>1</tenderId>
<returnTenderId>1</returnTenderId>
<amount>1.2</amount>
<accountId>1</accountId>
<subscriptionId>1</subscriptionId>
<chargeDescription>1</chargeDescription>
</BillToAccount>
</AddInsuranceToOrderForm>
Gives output:
<?xml version="1.0" encoding="UTF-8"?>
<BillToAccount xmlns="http://www.example.com/xml-namespace/">
<date>2012-10-01T23:59:59</date>
<lineNumber>line 1</lineNumber>
<tenderId>1</tenderId>
<returnTenderId>1</returnTenderId>
<amount>1.2</amount>
<accountId>1</accountId>
<subscriptionId>1</subscriptionId>
<chargeDescription>1</chargeDescription>
</BillToAccount>
I am using xsd:schema which will be used to generated desired xml, I have a title field in xsd:schema.
I want to validate it from xsd:schema only that whenever user try to put values more than 10 characters, it will generate the error.
Below is the part of my xsd:schema
<xsd:sequence>
<xsd:element name="Title" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>
<xsd:element name="City" minOccurs="0" maxOccurs="1" type="tcmi:SimpleLink">
<xsd:annotation>
<xsd:appinfo>
<tcm:linktype>ComponentLink</tcm:linktype>
<tcm:AllowMultimediaLinks>false</tcm:AllowMultimediaLinks>
<tcm:AllowedTargetSchemas>
<tcm:TargetSchema xlink:href="tcm:227-190428-8" xlink:title="City"/>
</tcm:AllowedTargetSchemas>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="FlightLinkText" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>
</xsd:sequence>
I means that can we validate it from <xsd:element name="Title" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>
Please suggest!
Have you tried something like:
<xsd:element name="Title" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:normalizedString">
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>