I have a question regarding WSDLs generated from CXF. From what I understood is that the WSDL that’s published by CXF is generated from JAX-WS/JAXB.
I have a WSDL file with the following content:
...
<xsd:complexType name="Scenario" mixed="true">
<xsd:sequence>
<xsd:element name="Description" type="xsd:anyURI" minOccurs="0"/>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xsd:sequence>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:complexType>
...
After I generated my classes and deployed the service I checked the interface in my browser (with ?wsdl). Much to my surprise it looked considerably different: a "choice" has been added, processContents is changed, etc.
...
<xsd:complexType mixed="true" name="Scenario">
<xsd:sequence>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="Description" type="xsd:string"/>
<xsd:any namespace="##other" processContents="lax"/>
<xsd:choice>
</xsd:sequence>
<xsd:anyAttribute namespace="##other" processContents="skip"/>
</xsd:complexType>
...
I am especially interested in this additional choice that’s been added?
Is it maybe because of the "xsd:any"?
Related
I'm trying to use some open-source software for RFID services (GitHub: fosstrak capturing application) from a few years ago and there's this error that I can't fix.
(null: 3, 230): cvc-elt.1: Cannot find the declaration of element 'change-set'.
I'm using Docker to containerise the application running Tomcat7 with Java8.
The XML looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<change-set xmlns="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.0/change-set.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd">
<add>
<resource source="classpath:drools/SimpleEPCISDocument.drl" type="DRL" />
</add>
</change-set>
And the XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:change-set="http://drools.org/drools-5.0/change-set">
<xsd:import namespace="http://www.w3.org/2001/XMLSchema-instance"/>
<xsd:element name="change-set">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="change-set:add"/>
<xsd:element ref="change-set:remove"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="add">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" ref="change-set:resource"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="remove">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" ref="change-set:resource"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="resource">
<xsd:complexType>
<xsd:sequence>
<xsd:any minOccurs="0"/>
<xsd:element minOccurs="0" ref="change-set:decisiontable-conf"/>
</xsd:sequence>
<!-- URL to the resource, can be file based -->
<xsd:attribute name="source" use="required" type="xsd:anyURI"/>
<!-- for example, DRL, or PKG -->
<xsd:attribute name="type" use="required" type="xsd:string"/>
<xsd:attribute name="basicAuthentication" type="xsd:string"/>
<xsd:attribute name="username" type="xsd:string"/>
<xsd:attribute name="password" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="decisiontable-conf">
<xsd:complexType>
<xsd:attribute name="input-type" use="required" type="xsd:NCName"/>
<xsd:attribute name="worksheet-name" use="required" type="xsd:NCName"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Change
xs:schemaLocation="http://drools.org/drools-5.0/change-set.xsd [...]
to
xs:schemaLocation="http://drools.org/drools-5.0/change-set [...]
because schemaLocation must be a series of pairs of namespace URIs and XSD locations. In this case, the namespace URI is http://drools.org/drools-5.0/change-set, which matches the namespace of the root element in your XML and the target namespace of your XSD.
See also
How to reference a local XML Schema file correctly?
You'll also have to deal with a subsequent Unique Particle Attribute issue, but that's a separate matter deserving its own question if you're unable to resolve. Start with XSD validation - ANY in SEQUENCE ("Unique Particle Attribution").
I am trying to bring in a set of groups called: DelegateGroup - Salesforce defines it as follows: DelegatedGroups
The meta data supplied shows the following:
<xsd:complexType name="DelegateGroup">
<xsd:complexContent>
<xsd:extension base="tns:Metadata">
<xsd:sequence>
<xsd:element name="customObjects" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
<xsd:element name="groups" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
<xsd:element name="label" type="xsd:string"/>
<xsd:element name="loginAccess" type="xsd:boolean"/>
<xsd:element name="permissionSets" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
<xsd:element name="profiles" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
<xsd:element name="roles" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
However this wasn't introduced until v36 so I went in and upgraded the Soap stubs to v46 - I am able to pull data from Salesforce, but I haven't figured out how to retrieve the DelegateGroup or how the accounts are associated with the delegategroup.
Note: The reason for the java tag is because I am coding this in Java.
Delegated Administrators can't be retrieved/deployed via metadata api. I think at best you'll get group names/permissions but not who's actually assigned. We know DelegateGroup and DelegateGroupMember objects exist (you can find them in online lists of obscure Salesforce object id prefixes) but they aren't exposed via API. See also https://salesforce.stackexchange.com/questions/129/querying-delegated-administrators
This is a continuity of My question
Assume below is my xsd file,
Updated XSD file
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/wm" xmlns="http://www.example.com/wm" elementFormDefault="qualified" version="1.0">
<xsd:include schemaLocation="Comm.xsd" />
<xsd:element name="testEame1">
<xsd:annotation>
<xsd:documentation> test </xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" minOccurs="1" />
<xsd:element name="session" type="rawSess" minOccurs="1" />
</xsd:sequence>
<xsd:attribute name="pid" type="xsd:integer" use="required" />
<xsd:attribute name="version" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
references another XSD which has type defined,
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" targetNamespace="http://www.example.com/wm" xmlns="http://www.example.com/wm" elementFormDefault="qualified">
<xsd:complexType name="rawSess">
<xsd:sequence>
<xsd:element name="oldSessionVersion" type="Sessiontype1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="sessInfo">
<xsd:sequence>
<xsd:element name="newSessionVersion" type="Sessiontype2" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Sessiontype1">
<xsd:sequence>
<xsd:element name="ele1" type="xsd:string" minOccurs="0" />
<xsd:element name="ele2" type="xsd:string" />
<xsd:element name="ele3" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Sessiontype2">
<xsd:sequence>
<xsd:element name="nele1" type="xsd:integer" minOccurs="0" />
<xsd:element name="nele2" type="xsd:integer" />
<xsd:element name="nele3" type="xsd:integer" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
In the above xml, for element session , I want it to have only two types like below. Either sessInfo or rawSess
<xsd:element name="session" type='sessInfo| rawSess' minOccurs="1"/>
Update Note : userDefinedtypes are complex types.
How can I configure my xsd to achieve this
If userDefinedType1 and userDefinedType2 are simple atomic types, then define a union type:
<xs:element name="session" type="one-or-two"/>
<xs:simpleType name="one-or-two">
<xs:union memberTypes="userDefinedType1 userDefinedType2"/>
</xs:simpleType>
We now know that they are actually complex types. Define a type
<xs:complexType name="eitherType">
<xs:choice>
<xs:sequence>... content model of alternative 1</xs:sequence>
<xs:sequence>... content model of alternative 2</xs:sequence>
</xs:choice>
</xs:complexType>
and reference this type from the element declaration.
NB: this only works if there is no ambiguity, that is, if the validator can work out which branch of the choice to take based on the first element name that it sees in the instance document. If your choice were between two content models that both start with an h1 element, for example, you would have to reorganise the content models to remove the ambiguity.
I have below xsd elements.
<xsd:element name="requestOne" type="tns:RequestOne"/>
<xsd:complexType name="RequestOne">
<xsd:annotation>
<xsd:documentation>some comment</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="requestTwo" type="tns:RequestTwo"/>
<xsd:complexType name="RequestTwo">
<xsd:annotation>
<xsd:documentation>other comment</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
It has two complex elements but inside them there is duplicated code. How can i refactor above code?
Thanks!
Instead of creating a new element you can use ref to refer to an existing one, tns in the sample below refers to the name space defined by the schema
<xsd:element name="id" type="xsd:string"/>
...
<xsd:complexType name=RequestOne">
<xsd:sequence>
<xsd:element ref="tns:id" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
...
Though, this does not really reduces the number of characters to write, in that simple case. You might even have a look at how to define abstract types which, similar to object orientated languages, get inherited by children:
<xsd:complexType name="AbstractType" abstract="true">
<xsd:sequence>
<xsd:element name"BaseType">
<xs:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1" >
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
the children now need to inherit from the abstract type in the following manner:
<xsd:complexType name="ChildOne">
<xsd:complexContent>
<xsd:extension base="tns:AbstractType">
<xsd:element name="newElement" type="xsd:string" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Where newElement is just a new element defined by the child.
Edit: to be more precise, the id element is not really inherited like in an object oriented language but you achieve the same effect. The difference is, that you have to add the base-type within the XML of the concrete realization.
<ChildOne>
<BaseType>
<id>someId</id>
</BaseType>
<!-- elements defined by child one goes here -->
<newElement>new Element</newElement>
</ChildOne>
I have an element A which can be of simple element as well as complex which gets created dynamically.
sample xml is here :
<A>john</A>
<A>
<B>kathy</B>
<C> bat </C>
</A>
my xsd is like this :
<xsd:element name="A">
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:sequence>
<xsd:element name="B" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="C" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
</xsd:element>
But here i am facing an exception which says :
Element 'A' cannot have character [children], because the type's content type is element-only
You need to specify mixed content in your type:
<xsd:element name="A">
<xs:complexType mixed="true">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:sequence>
<xsd:element name="B" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="C" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
Also it's a bit redundant having a sequence inside a choice. You either want a sequence or not.
Hope that helps.