Notepad ++ document labelled utf-16 but has utf-8 content - xsd

I get this error message'document labelled utf-16 but has utf-8 content' when i validate my xsd in notepad ++. What could be the cause ? Here is my xsd :
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Member">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Request">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Transaction">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Number" type="xsd:int" />
<xsd:element name="DateTime" type="xsd:decimal" />
<xsd:element name="TestIndicator" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Membership">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MembershipNumber" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="xs:schemaLocation" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>

Change the encoding line to read utf-8 instead of utf-16 (very top of your xml file).

There is a bug open in Notepad++ issues tracker for something similar: https://sourceforge.net/p/npp-plugins/bugs/166/
May be your file has an encoding which match the header but the XML plugin shows an inappropriate error.
Check if Notepad++ show UCS-2 in its status bar (UTF-16 is an extension of UCS-2). If it's there, you are OK because there is only ASCII 7 bit characters in your file apparently.

Related

Unmarshal Jaxb class error

I have a xml string which is a response from third party server.
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<GetRateQuoteResponse>
<GetRateQuoteResult>
</GetRateQuoteResult>
</GetRateQuoteResponse>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
I want to parse it in JAX-WS.
So i converted this String to xsd file using this web site
The web site gave me the xsd as follows.
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="SOAP-ENV:Envelope">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SOAP-ENV:Body">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="GetRateQuoteResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="GetRateQuoteResult" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I now generate JaxB classes from this xsd, it tries to create class named
SOAP-ENV:Envelope and SOAP-ENV:Body which is invalid name for a class and it fails to do so.
Also even if i modify xsd to Envelope and Body the Unmarshalling fails.
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}SOAP-ENV:Envelope>
Please guide.
The XSD should not contain any SOAP elements; only the WSDL does. The XSD by definition is or data only. The transport protocol information (SOAP) should not be in the data definition as XSDs have applications outside of SOAP.
Omit the SOAP schema elements from the entry you pass to the XSD generato. By including that stuff in there, you're indicating to the generator that those elements will be part of your JAXB-generated classes (which shouldn't be the case). What you should feed the generator is the excerpt below, which would rightly generate the GetRateQuoteResponse-containing schema
<GetRateQuoteResponse>
<GetRateQuoteResult>
</GetRateQuoteResult>
</GetRateQuoteResponse>
The result:
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="GetRateQuoteResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="GetRateQuoteResult" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Backward compatibility of Webservice operation output messages in case of a xsd choice extension

I have a question about backward compatibility of a Webservice interface in context of choices in output message. Couldn't really find an answer to that.
Let's assume I have a Webservice with an operation "getData" which has the following response message (this is V1 of the Webservice). The response message includes a choice element which gives back either the payload of "Instruction" or "KeyTranslation". This V1 WSDL is used by various consumer which are generating the java bindings and rolling out the application in production.
<xsd:complexType name="GetInstructionListResponse">
<xsd:sequence>
<xsd:element name="ContinueInfo" type="tns:ContinueInfo" form="qualified" />
<xsd:element name="ResultLength" type="xsd:integer" form="qualified" />
<xsd:element name="Payload">
<xsd:complexType>
<xsd:choice>
<xsd:element name="DataObjectList1" type="tns:Instruction" form="qualified" minOccurs="1" maxOccurs="50" />
<xsd:element name="DataObjectList2" type="tns:KeyTranslation" form="qualified" minOccurs="1" maxOccurs="50" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="ReturnCodeList" type="tns:ReturnCodeList" form="qualified" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Description: List of error descriptions</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
As a provider of this interface we would introduce now a third choice element "Advise" after the rollout of V1.
<xsd:complexType name="GetInstructionListResponse">
<xsd:sequence>
<xsd:element name="ContinueInfo" type="tns:ContinueInfo" form="qualified" />
<xsd:element name="ResultLength" type="xsd:integer" form="qualified" />
<xsd:element name="Payload">
<xsd:complexType>
<xsd:choice>
<xsd:element name="DataObjectList1" type="tns:Instruction" form="qualified" minOccurs="1" maxOccurs="50" />
<xsd:element name="DataObjectList2" type="tns:KeyTranslation" form="qualified" minOccurs="1" maxOccurs="50" />
<xsd:element name="DataObjectList2" type="tns:Advice" form="qualified" minOccurs="1" maxOccurs="50" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="ReturnCodeList" type="tns:ReturnCodeList" form="qualified" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Description: List of error descriptions</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Question is now, is this change in the output message a breaking change, i.e does an existing consumer (working with V1 which doesn't require the new choice element) has to do anything (e.g. to regenerate the java bindings, any marshalling problems?) in case we would replace as a provider the V1 WSDL provider interface with this extended response structure or would that be transparent for him as long he doesn't require the third choice element in its processing?
By a strict definition, I would call this a breaking change. By "strict", I mean that it's possible to write a program which will work before the change, and break after the change. Any program that would have received one of the two original choices before the change, but now will receive the third choice - this program will be broken.
Furthermore, any program which can read the WSDL will see that it changed. Such a program could reasonably be permitted to "break" if the WSDL changes.
Keep in mind that, when using a tool like wsdl2java or "Add Service Reference" in Visual Studio, code is being written from the WSDL. A change in the WSDL will result in a change in the generated code. Don't take it lightly that you could be changing someone's code without their knowledge.
In the meantime I was setting up a test bed (Eclipse, ApacheV6, Axis2) and was running a test:
Having a client which was using WSDL java bindings of V1 of the server (two choice elements)
Having a server running with WSDL V2 implementation having three choices.
Result: Java client could still connect and getting correct results for the two choice elements back from the V2 server (no marshalling problem, no recompile necessary).

XSD two elements with the same inner structure

I am working with an xsd, trying to get it to validate an xml.
The xml is used to create objects. There are two types of objects that can be created by the elements in the list: SC and SMSC. SMSC is an SC, and extends it.
SMSC doesn't contain any new properties. From the perspective of the xml, an SMSC is identical to an SC in every way, except that the elements that define its properties are wrapped by <SMSC> tags instead of <SC> tags.
Our XSD looks like this:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name='Definitions'>
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="SC">
<!--SNIP properties of SC and SMSC -->
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Is there a way to change this to allow either SC or SMSC as the element, other than duplicating all of the property definitions in an SMSC element? We don't want to have to double the length of the document and duplicate all of the property definitions.
As it stands, the only validation error we have in our XML is where we have an SMSC element. If there isn't a way to fix this without duplicating all the property definitions we'll leave it as-is, but we'd obviously prefer to eliminate the warning this throws if practical.
While it is confusing by tags instead of tags, I would think that below is either answering your question, or elicits better explanations.
So, what you see is avoiding duplication; you don't actually need the additional type SMSC (see Definitions2), but I've put it just in case (Definitions). Making the SMSC element of the SC type would work exactly the same.
The difference between Definitions / Definitions2 and Definitions3 is that one uses substitution groups instead of choices. I personally prefer substitution groups to choices, yet is not that uncommon to run into issues related to substution groups (i.e. they are poorly supported here and there).
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" xmlns="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="SC">
<xsd:sequence>
<!-- Stuff goes here -->
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="SMSC">
<xsd:complexContent>
<xsd:extension base="SC"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Definitions">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="SC" type="SC"/>
<xsd:element name="SMSC" type="SMSC"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<!-- Another way -->
<xsd:element name="Definitions2">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="SC" type="SC"/>
<xsd:element name="SMSC" type="SC"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="Definitions3">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="SC" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="SC" type="SC" />
<xsd:element name="SMSC" type="SMSC" substitutionGroup="SC" />
</xsd:schema>

Invalid particle derivation by restriction for schema

How can I remove the below warning in the xsd. mymain.xsd refers to mysecond.xsd
my main.xsd
<?xml version="1.0" encoding="UTF-8"?><xsd:schema elementFormDefault="qualified" targetNamespace="http://abc.com" version="2.0" xmlns:tyu="http://abc.com" xmlns:my="def.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="def.com" schemaLocation="mysecond.xsd"/>
<xsd:complexType name="myType">
<xsd:complexContent>
<xsd:restriction base="my:myType">
<xsd:sequence>
<xsd:element minOccurs="0" name="rty" type="tyu:myagainType"/>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="myagainType">
<xsd:complexContent>
<xsd:restriction base="my:myagainType">
<xsd:sequence>
<xsd:element minOccurs="1" name="uid">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
mysecond.xsd
<?xml version="1.0" encoding="UTF-8"?><xsd:schema elementFormDefault="qualified" targetNamespace="def.com" version="2.0" xmlns:my="def.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="myagainType">
<xsd:sequence>
<xsd:element minOccurs="0" name="klo" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="myType">
<xsd:sequence>
<xsd:element minOccurs="0" name="rty" type="my:myagainType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
warning
Warning 1 Invalid particle derivation by restriction - 'Derived element 'http://abc.com:rty' is not a valid restriction of base element 'def.com:rty' according to Elt:Elt -- NameAndTypeOK.'. D:\files\mymain.xsd 3 4
Short answer, you cannot. To begin with, your rty in mySecond.xsd is locally defined and qualified and in a different namespace than the "equivalent" rty in the main.xsd, the latter also locally defined and qualified in a different namespace.
If you go through the XML Schema spec, part 2, you'll get an explanation for each rule that applies to a valid restriction. In your case, you either use the same named element (start by "unqualifying" the rty element), or a member of a substitution group.
You obviously don't want the same element, since it'll give you the same content model - you have one element only. One reason people use restriction is to reduce the content model (remove elements from the list) and/or fiddle with min/maxOccurs for particles.
You can't do things using substitution groups since you defined rty locally; the head of a substitution group must be defined globally.
To allow for what you want, you have to completely rewrite your XSD. A better description around what exactly you're trying to achieve along with any constraints you place on XSD authoring (e.g. use of substitution groups, or redefine, or the context in which your XSDs will be used) may help others provide you with better answers.

Perl XSD parsing

I have a XSD file that is to be parsed and converted into a XML file.
Is there any way to do it using Perl ??? After xml file is generated, i have to parse that xml file which is the second part, but i was struck in the first part of converting the XSD file to XML format.
XSD is given below
<?xml version="1.0" encoding="UTF-8"?>
<!-- This document was generated by the Objective Systems ASN2XSD Compiler
(http://www.obj-sys.com). Version: 6.3.0, Date: 06-May-2010. -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.obj-sys.com/S1AP-PDU-Descriptions"
targetNamespace="http://www.obj-sys.com/S1AP-PDU-Descriptions"
xmlns:S1AP-CommonDataTypes="http://www.obj-sys.com/S1AP-CommonDataTypes"
xmlns:S1AP-PDU-Contents="http://www.obj-sys.com/S1AP-PDU-Contents"
xmlns:S1AP-Constants="http://www.obj-sys.com/S1AP-Constants"
xmlns:asn1="http://www.obj-sys.com/v1.0/XMLSchema"
elementFormDefault="qualified">
<xsd:import namespace="http://www.obj-sys.com/S1AP-CommonDataTypes"
schemaLocation="S1AP-CommonDataTypes.xsd"/>
<xsd:import namespace="http://www.obj-sys.com/S1AP-PDU-Contents"
schemaLocation="S1AP-PDU-Contents.xsd"/>
<xsd:import namespace="http://www.obj-sys.com/S1AP-Constants"
schemaLocation="S1AP-Constants.xsd"/>
<xsd:import namespace="http://www.obj-sys.com/v1.0/XMLSchema"
schemaLocation="http://www.obj-sys.com/v1.0/XMLSchema/asn1.xsd"/>
<!-- PDU definition -->
<xsd:element name="s1AP-PDU" type="S1AP-PDU"/>
<xsd:complexType name="S1AP-PDU">
<xsd:choice>
<xsd:element name="initiatingMessage" type="InitiatingMessage"/>
<xsd:element name="successfulOutcome" type="SuccessfulOutcome"/>
<xsd:element name="unsuccessfulOutcome" type="UnsuccessfulOutcome"/>
<xsd:any namespace="##other" processContents="lax"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="InitiatingMessage">
<xsd:sequence>
<xsd:element name="procedureCode" type="S1AP-CommonDataTypes:ProcedureCode"/>
<xsd:element name="criticality" type="S1AP-CommonDataTypes:Criticality"/>
<xsd:element name="value" type="asn1:OpenType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="SuccessfulOutcome">
<xsd:sequence>
<xsd:element name="procedureCode" type="S1AP-CommonDataTypes:ProcedureCode"/>
<xsd:element name="criticality" type="S1AP-CommonDataTypes:Criticality"/>
<xsd:element name="value" type="asn1:OpenType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="UnsuccessfulOutcome">
<xsd:sequence>
<xsd:element name="procedureCode" type="S1AP-CommonDataTypes:ProcedureCode"/>
<xsd:element name="criticality" type="S1AP-CommonDataTypes:Criticality"/>
<xsd:element name="value" type="asn1:OpenType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
It looks like you used one of the free tools from Objective Systems to convert some ASN.1 data. I believe that you used their tool, ASN2XSD, when you meant to use their ASN2XML tool instead. The XSD tool produces a description document like the one you show in your question that helps another tool format and describe your data, which is not what you wanted.
If you use their ASN2XML tool from the first link above to convert your ASN.1 data, it will produce the XML output you need without losing any data. You can then use Perl's XML tools to parse that data.

Resources