How to validate XSD in Swift? - swift

I have i.e. this XML:
<?xml version="1.0" encoding="UTF-8" ?>
<individual>
<name>Baeldung</name>
<address>
<zip>00001</zip>
<city>New York</city>
</address>
</individual>
and would validate, wether it matches this schema:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="individual">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="zip" type="xs:positiveInteger" />
<xs:element name="city" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Is it any Swift technic to do it?
I looked at Apple XMLDocument library, but it does DTD validation. I think this is something else: https://developer.apple.com/documentation/foundation/xmldocument
Found this online tool, but it is not Swift: https://www.liquid-technologies.com/online-xsd-validator

Related

What is the correct format for SOAP data? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a file, I shared it here http://codepad.org/V6FR2Wbs
It seems this file contains SOAP data. But I do not confirm that this contains SOAP data.
So I want to know, is there any specific format for SOAP data.
I got a similar question here What is the correct format of a SOAP response, but I don't see any format related information there.
There is very simple way to validate if request or response SOAPMessage is valid or not.
As a part of SOAP Message, it includes the namespace that points to SOAP XSD aka. XML schema definition, and the message be valid as per that XSD.
In your example, the SOAP message is--
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"> <SOAP-ENV:Header> <cwmp:ID SOAP-ENV:mustUnderstand="1">279384</cwmp:ID> </SOAP-ENV:Header> <SOAP-ENV:Body> <cwmp:Inform> <DeviceId> <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer> <OUI>00259E</OUI> <ProductClass>EG8040H5</ProductClass> <SerialNumber>48575443FF5E5D9D</SerialNumber> </DeviceId> <Event SOAP-ENC:arrayType="cwmp:EventStruct[1]"> <EventStruct> <EventCode>2 PERIODIC</EventCode> <CommandKey/> </EventStruct> </Event> <MaxEnvelopes>1</MaxEnvelopes> <CurrentTime>2019-06-19T15:30:33+00:00</CurrentTime> <RetryCount>0</RetryCount> <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[8]"> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name> <Value xsi:type="xsd:string">http://10.240.12.35:7547/1d9564b694ef18090a9377cd6f3217eb</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceSummary</Name> <Value xsi:type="xsd:string">InternetGatewayDevice:1.4[](Baseline:1, EthernetLAN:1, WiFiLAN:2, Time:1, IPPing:1, DeviceAssociation:1)</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name> <Value xsi:type="xsd:string">1.0</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name> <Value xsi:type="xsd:string">172D.A</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name> <Value xsi:type="xsd:string">V5R019C00S115</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name> <Value xsi:type="xsd:string">10.240.12.35</Value> </ParameterValueStruct> </ParameterList> </cwmp:Inform> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
In your example SOAP schema is located as http://schemas.xmlsoap.org/soap/envelope/
And the XSD for that schema is--
<?xml version='1.0' encoding='UTF-8' ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" >
<!-- Envelope, header and body -->
<xs:element name="Envelope" type="tns:Envelope" />
<xs:complexType name="Envelope" >
<xs:sequence>
<xs:element ref="tns:Header" minOccurs="0" />
<xs:element ref="tns:Body" minOccurs="1" />
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax" />
</xs:complexType>
<xs:element name="Header" type="tns:Header" />
<xs:complexType name="Header" >
<xs:sequence>
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="lax" />
</xs:complexType>
<xs:element name="Body" type="tns:Body" />
<xs:complexType name="Body" >
<xs:sequence>
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:sequence>
<xs:anyAttribute namespace="##any" processContents="lax" >
<xs:annotation>
<xs:documentation>
Prose in the spec does not specify that attributes are allowed on the Body element
</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
<!-- Global Attributes. The following attributes are intended to be usable via qualified attribute names on any complex type referencing them. -->
<xs:attribute name="mustUnderstand" >
<xs:simpleType>
<xs:restriction base='xs:boolean'>
<xs:pattern value='0|1' />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="actor" type="xs:anyURI" />
<xs:simpleType name="encodingStyle" >
<xs:annotation>
<xs:documentation>
'encodingStyle' indicates any canonicalization conventions followed in the contents of the containing element. For example, the value 'http://schemas.xmlsoap.org/soap/encoding/' indicates the pattern described in SOAP specification
</xs:documentation>
</xs:annotation>
<xs:list itemType="xs:anyURI" />
</xs:simpleType>
<xs:attribute name="encodingStyle" type="tns:encodingStyle" />
<xs:attributeGroup name="encodingStyle" >
<xs:attribute ref="tns:encodingStyle" />
</xs:attributeGroup>
<xs:element name="Fault" type="tns:Fault" />
<xs:complexType name="Fault" final="extension" >
<xs:annotation>
<xs:documentation>
Fault reporting structure
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="faultcode" type="xs:QName" />
<xs:element name="faultstring" type="xs:string" />
<xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
<xs:element name="detail" type="tns:detail" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="detail">
<xs:sequence>
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xs:sequence>
<xs:anyAttribute namespace="##any" processContents="lax" />
</xs:complexType>
</xs:schema>
Using any programming language or API or online service, you could validate the SOAP message against the given XSD manually or automated way.
E.g.
As I did using this online service(https://www.liquid-technologies.com/online-xsd-validator) and your SOAP message found valid against the schema.

SOAP Payload with nested complexType

I'm trying to make a SOAP request where a parameter is a complex type, and I'm having trouble getting the syntax right.
WSDL: https://www.dayforcehcm.com/DataSvc/DayforceService.svc?singleWsdl
Action: IDayforceService/Query
Here is the SOAP request that was generated by SoapUI:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://Dayforce/Services/DayforceService">
<SOAP-ENV:Body>
<ns1:Query>
<ns1:sessionTicket>?</ns1:sessionTicket>
<ns1:request/>
</ns1:Query>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
My question is how to fill in the <ns1:request/> element. The request should be a GetReportDefinitionsRequest, and it needs to provide a string value for XRefCode.
SoapUI isn't being much help here, and WSDL to class generators I've tried have similar problems. At this point I'd settle for just knowing the proper XML syntax
Here are the relevant types (also available in the WSDL above).
Query:
<xs:element name="Query">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="sessionTicket" nillable="true" type="xs:string"/>
<xs:element xmlns:q9="http://Dayforce/Services/Data" minOccurs="0" name="request" nillable="true" type="q9:DFRequest"/>
</xs:sequence>
</xs:complexType>
</xs:element>
GetReportDefinitionsRequest:
<xs:complexType name="GetReportDefinitionsRequest">
<xs:complexContent mixed="false">
<xs:extension base="tns:DFRequest">
<xs:sequence>
<xs:element minOccurs="0" name="XRefCode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="GetReportDefinitionsRequest" nillable="true" type="tns:GetReportDefinitionsRequest"/>
DFRequest:
<xs:complexType name="DFRequest">
<xs:complexContent mixed="false">
<xs:extension base="tns:DFObject">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="DFRequest" nillable="true" type="tns:DFRequest"/>
DFObject:
<xs:complexType name="DFObject">
<xs:sequence/>
</xs:complexType>
<xs:element name="DFObject" nillable="true" type="tns:DFObject"/>
I was able to get the sample code running and hook in to get the XML generated for the request. Here's the result, in case it helps anyone in the future.
The important part is to assign the type attribute to the tag. That involves importing the http://www.w3.org/2001/XMLSchema-instance namespace to get the type attribute, and the http://Dayforce/Services/Data namespace for the type itself.
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dfs="http://Dayforce/Services/DayforceService">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<dfs:Query>
<dfs:sessionTicket>?</dfs:sessionTicket>
<dfs:request
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dfd="http://Dayforce/Services/Data"
i:type="dfd:GetReportDefinitionsRequest">
<dfd:XRefCode>?</dfd:XRefCode>
</dfs:request>
</dfs:Query>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

XML to CSV with data header using Liquid Data Mapper

I have an XML file that describes a header and a list. I need to generate a CSV file where the first line of the file is constructed from the header information and the subsequent lines of the file constructed from the list. The header has a different number of columns to the list items.
This is easy to do with xsl. How can I do it with the data mapper using the .NET mapping engine?
A simple example to explain. XSD of input xml
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="A" />
<xs:element name="B" />
<xs:element name="Line" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="C" />
<xs:element name="D" />
<xs:element name="E" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
An Example Input XML
<Root>
<A>Header Value</A>
<B>112233</B>
<Line>
<C>22</C>
<D>Fred</D>
<E>1</E>
</Line>
<Line>
<C>34</C>
<D>Jim</D>
<E>2</E>
</Line>
<Line>
<C>42</C>
<D>Amanda</D>
<E>1</E>
</Line>
<Line>
<C>1267</C>
<D>Vickie</D>
<E>2</E>
</Line>
</Root>
Required Text Output:
Header Value|112233
22|Fred|1
34|Jim|2
42|Amanda|1
1267|Vickie|2
Generating either
Header Value|112233
or
22|Fred|1
34|Jim|2
42|Amanda|1
1267|Vickie|2
as individual csv files is easy (as it should be) but how can I can't see how to produce the required file other than resorting back to xslt.
You can set up a transform that looks something like this if you want to be able to dynamically set the headers.
You double up the 'Row' inputs using the 'Duplicate' option
Before you do that you need to tweak your schema. The input values A-E need typing (note the type="xs:string").
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2019 (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="A" type="xs:string" />
<xs:element name="B" type="xs:string" />
<xs:element name="Line" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="C" type="xs:string" />
<xs:element name="D" type="xs:string" />
<xs:element name="E" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This will give you output data that looks like this (note it always outputs 3 columns, so you get a trailing '|').
Header Value|112233|
22|Fred|1
34|Jim|2
42|Amanda|1
1267|Vickie|2
If you just want the data and no header then you can just connect it up like this

Stream binary part of a message from BizTalk orchestration

I must send a MTOM request to a WCF service that expects the following schema as input:
<xs:complexType name="BinaryRequest">
<xs:sequence>
<xs:element minOccurs="0" name="requestContent" nillable="true" type="BinaryRequestContent" />
</xs:sequence>
</xs:complexType>
<xs:element name="BinaryRequest" nillable="true" type="BinaryRequest" />
<xs:complexType name="BinaryRequestContent">
<xs:sequence>
<xs:element minOccurs="0" name="partData" nillable="true" type="xs:base64Binary" />
<xs:element minOccurs="0" name="partNumber" type="xs:int" />
<xs:element minOccurs="0" name="transactionId" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="BinaryRequestContent" nillable="true" type="BinaryRequestContent" />
As you can see the "partData" property is of type byte[] and I would like to have the posibility to stream it and send it in a separated MIME part.
Using the example from http://seroter.wordpress.com/biztalk-and-wcf-part-iv-attachment-patterns/ is not possible because my binary data is only a part of the response.
Any idea how to do this?
I have a test solution but the binary content is send inline as base64 not separated as an attachment
https://docs.google.com/file/d/0B1M277-_UZ35Si1JWWw5Nm9ia0E/edit?usp=sharing

Referencing ComplexType Elements within ComplexType/Sequence Elements in XSD

I am trying to construct a xsd file (inside a WSDL) to get data from a SOAP Request. I have the expected soap Request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:upsertEntity xmlns:m="http://www.boomi.com/connector/wss">
<eTimeRequest>
<ObjectType>String</ObjectType>
<Action>String</Action>
<eTimeID>String</eTimeID>
<OperativeID>String</OperativeID>
</eTimeRequest>
</m:upsertEntity>
</SOAP-ENV:Body>
Here is what I have tried. You can not have a <xs:ComplexType> within another one. I have tried the referencing approach, but apparently, when I tried to do a SOAP Request with it, it was invalid. What can I do?
Here is the XSD within the WSDL:
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.boomi.com/connector/wss">
<xs:element name="eTimeRequest" type="eTimeRequest"/>
<xs:complexType name="eTimeRequest">
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="0" name="ObjectType" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="Action" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="eTimeID" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="OperativeID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="upsertEntity" type="tns:upsertEntity"/>
<xs:complexType name="upsertEntity">
<xs:sequence>
<xs:element minOccurs="0" type="eTimeRequest"/> <!-- These should be the ObjectType, Action, eTimeID and OperativeID in here -->
</xs:sequence>
</xs:complexType>
</xs:schema>
EDIT
Another thing I noticed in the code I linked was that I used the Type="eTimeRequest" and not ref="eTimeRequest". No matter though, still invalid. Here is the error message I get on validation:
Invalid XML schema: ''eTimeRequest' must refer to an existing element.'
Sorry for those who have read this. I obviously made a mistake in my XSD code, and wasted time doing so.
It's true, <xs:ComplexType> is NOT ALLOWED in <xs:ComplexType>, but <xs:Element> containing <xs:ComplexType> is allowed in <xs:ComplexType>. The original SOAP Request generated was therefore invalid. I ran the new version through our system and it worked.
The Correct XSD Schema in the WSDL should have read:
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.boomi.com/connector/wss">
<xs:element name="upsertEntity" type="tns:upsertEntity"/>
<xs:complexType name="upsertEntity">
<xs:sequence>
<xs:element name="eTimeRequest">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="0" name="ObjectType" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="Action" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="eTimeID" type="xs:string"/>
<xs:element maxOccurs="1" minOccurs="0" name="OperativeID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>