responses:
200:
body:
application/xml:
example: |
<?xml version="1.0" encoding="UTF-8"?>
<my_response>
<result>success</result>
<message>great</message>
</my_response>
Is this a valid inline application/xml body example for RAML endpoint definition? If not how should it be?
Yes it is.
Depending on what you want to do you may want to also specify the type using XSD.
For example:
/jobs:
displayName: Jobs
post:
description: Create a Job
body:
text/xml:
type: |
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="api-request">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="input"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Also there are some special keywords used for XML serialization: https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#xml-serialization-of-type-instances
Related
Not looking to do anything spectacular here, just looking for, really, any sort of simple xslt which will run from xsltproc and give reasonably interesting output -- but simple.
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ ls
a.xslt shiporder.xml
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ cat shiporder.xml
<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ trang shiporder.xml shiporder.xsd
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ ls
a.xslt shiporder.xml shiporder.xsd xsi.xsd
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ cat shiporder.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element maxOccurs="unbounded" ref="item"/>
</xs:sequence>
<xs:attribute name="orderid" use="required" type="xs:integer"/>
<xs:attribute ref="xsi:noNamespaceSchemaLocation" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:NCName"/>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element minOccurs="0" ref="note"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:integer"/>
<xs:element name="price" type="xs:decimal"/>
</xs:schema>
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ cat xsi.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:import schemaLocation="shiporder.xsd"/>
<xs:attribute name="noNamespaceSchemaLocation" type="xs:NCName"/>
</xs:schema>
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ cat a.xslt
<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:copy-of select="unparsed-text(static-base-uri())"/>
</xsl:template>
</xsl:stylesheet>
thufir#dur:~/jaxb/ship$
thufir#dur:~/jaxb/ship$ xsltproc a.xslt shiporder.xml > output.xml
compilation error: file a.xslt line 1 element stylesheet
xsl:version: only 1.1 features are supported
xmlXPathCompOpEval: function static-base-uri not found
XPath error : Unregistered function
xmlXPathCompiledEval: evaluation failed
no result for shiporder.xml
thufir#dur:~/jaxb/ship$
The xml is from w3school -- frankly, just looking to generate some sort of output using xsltproc, which means xslt version 1, I believe.
xsltproc uses the libxsltprocessor which supports only XSLT 1.0 or 1.1 (in some configurations).
Your XSLT contains:
<xsl:copy-of select="unparsed-text(static-base-uri())"/>
static-base-uri() is an XPath 2.0 function, and your processor cannot handle it - which is why you see:
xmlXPathCompOpEval: function static-base-uri not found
XPath error : Unregistered function
Note that unparsed-text() is an XSLT 2.0 function and you would get an error with it too, if the processor ever got that far.
just looking to generate some sort of output using xsltproc
Try the identity transform for starters?
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>
I have following example xml message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<to>...</to>
<from>...</from>
<id>..</id>
<relatesTo>...</relatesTo>
<action>...</action>
<version>...</version>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<customComplexElement>
<a>a_v</a>
<b>b_v</b>
<c>c_v</c>
<d>d_v</d>
<e>e_v</e>
<f>f_v</f>
</customComplexElement>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
From which I have generated a xsd file with use of one of online tools:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="id" type="xs:string"/>
<xs:element name="relatesTo" type="xs:string"/>
<xs:element name="action" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
<xs:element name="customComplexElement">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="a"/>
<xs:element type="xs:string" name="b"/>
<xs:element type="xs:string" name="c"/>
<xs:element type="xs:string" name="d"/>
<xs:element type="xs:string" name="e"/>
<xs:element type="xs:string" name="f"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then I generate the appropriate header file with wsdl2h.exe and then compile it with soapcpp2.exe compiler.
Then I try to read xml file with a function soap_read_customComplexElement() and all I get is SOAP_TAG_MISMATCH. This method seems to work if I get rid of all the soap stuff the message but I wonder if there are some functions in gSOAP to parse soap envelope, header and body?
I've had same problem. But i've just fixed it.
So, in my case i use this line of code.
struct soap *soap = soap_new1(SOAP_C_UTFSTRING | SOAP_XML_IGNORENS | SOAP_XML_TREE);
The key paramter is SOAP_XML_IGNORENS. This parameter ignore namespaces.
SOAP_XML_IGNORENS in: ignores the use of XML namespaces in input
The root of this problem is that you don't declare namespaces in your body content. That why gSoap don't know how to convert this xml.
This wouldn't be converted, because gSoap don't know what is ns4:
<ns4:ParseKeywords><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>
But if i declare namespace it will be converted
<ns4:ParseKeywords xmlns:ns4="com.idurdyev.idcommerce:ParseKeywords:1.0"><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>
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.
I've been playing with gSOAP XML Data Binding and noticed that class generation varies depending on the XML schema style. Let me show you an example:
library.xml:
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book isbn="0132350882"/>
<book isbn="020161622X"/>
<book isbn="0201633612"/>
</library>
Case 1: XML schema written in the Russian doll style
library.xsd (Russian doll style - generated by Visual Studio 2010 from XML above):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="book">
<xs:complexType>
<xs:attribute name="isbn" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I am using the following sequence in order to get proxy files (header and source):
c:\test\gSOAP_Test1>wsdl2h.exe -t "c:\tools\gsoap_2.8.6\gsoap-2.8\gsoap\typemap.dat" Library.xsd
c:\test\gSOAP_Test1>soapcpp2.exe -I "c:\tools\gsoap_2.8.6\gsoap-2.8\gsoap\import" Library.h
For Russian doll styled XSD gSOAP generates classes with following design:
soapStub.h:
class SOAP_CMAC _ns1__library_book
{
public:
std::string isbn; /* required attribute */
...
};
class SOAP_CMAC _ns1__library
{
public:
std::vector<_ns1__library_book >book; /* required element of type ns1:library-book */
...
};
Note that _ns1__library's member book is implemented as vector of _ns1__library_book objects. But this is not the case when we provide schema written in other styles where it is implemented as vector of pointers.
Case 2: XML schema written in the Venetian blind style
library.xsd (Venetian blind):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="book_t">
<xs:attribute name="isbn" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="library_t">
<xs:sequence>
<xs:element name="book" type="book_t" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="library" type="library_t"/>
</xs:schema>
soapStub.h:
class SOAP_CMAC ns1__book_USCOREt
{
public:
std::string isbn; /* required attribute */
...
};
#endif
class SOAP_CMAC ns1__library_USCOREt
{
public:
std::vector<ns1__book_USCOREt * >book; /* required element of type ns1:book_t */
...
};
Case 3: XML schema written in the Sliced salami style
library.xsd (Sliced salami):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:attribute name="isbn" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element ref="book" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
soapStub.h:
class SOAP_CMAC _ns1__book
{
public:
std::string isbn; /* required attribute */
...
};
#endif
class SOAP_CMAC _ns1__library
{
public:
std::vector<_ns1__book * >ns1__book; /* required element of type ns1:book */
...
}
For the XML provided, I prefer _ns1__library's book collections member to be vector of objects - not a vector of pointers. I want to create instance of _ns1__book on the stack and simply pass it (by reference) to vector's push_back(). This is possible only for Russian doll-styled schemas.
How to force gSOAP to generate collection of elements member as vector of objects for any schema style? Shall some special arguments be provided to wsdl2h.exe and/or soapcpp2.exe? Shall XML schema document contain any additional elements?