unable to parse unmarshall xsi:nil=true with jibx - axis2

I am receiving a soap message from an external server that is sending xsi:nil tag for a boolean element.
JIBX complains about an invalid boolean value and its not able to parse this xml.
How can I overcome this problem?
incoming xml:
<materialChange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
the xsd:
<s:element minOccurs="0" maxOccurs="1" name="materialChange" type="s:boolean" nillable="true"/>

Related

Invalid XML element location. (SQL-XSD)

I just started learning XML today. I was trying to create a 'sample' XSD and populate it but.. I made up my data and it looks fine, but I can't make this schema work..
CREATE XML SCHEMA COLLECTION GenreTestSchema
AS
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--create group for GENRELIST-->
<xsd:group name="GENRELISTGROUP">
<xsd:element name="GENRELIST">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="GENRE" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="REFERENCE" minOccurs="0" maxOccurs="100" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:group>
</xsd:schema>
Now If I remove this element
<xsd:element name="GENRELIST">
and all the code that goes with it so (element and complextype) then the schema works fine. I can't figure out what is wrong here and why it doesn't let me create this element?
Errorlog
Element <element> is not valid at location '/*:schema[1]/*:group[1]/*:element[1]'.
It talks about invalid location but I literally have no idea why?
Data sample
<GENRELIST xmlns="http://myGenres">
<GENRE GenreNo="1">
<GENRE>Fiction</GENRE>
<REFERENCE>Alien</REFERENCE>
</GENRE>
<GENRE GenreNo="2">
<GENRE>Tragedy</GENRE>
<REFERENCE>Titanic</REFERENCE>
</GENRE>
</GENRELIST>
The problem is that you're missing to take the namespace xmlns="http://myGenres" into account on the element GENRELIST.
So transform your anonymous complex type to a named type and use the namespace on it:
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gl="http://myGenres"
targetNamespace="http://myGenres"
elementFormDefault="qualified">
<xsd:complexType name="genrelist"> <!-- named type 'genrelist' -->
<xsd:sequence>
<xsd:element name="GENRE" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="REFERENCE" minOccurs="0" maxOccurs="100" />
</xsd:sequence>
</xsd:complexType>
<!--create group for GENRELIST-->
<xsd:element name="GENRELIST" type="gl:genrelist" /> <!-- applying the 'gl' namespace to named type 'genrelist' -->
</xsd:schema>
This way your XML will be validated.
For the purpose of targetNamespace look here and for
elementFormDefault look there.
I don't know why you're trying to create an xs:group (a "model group"). A model group is a reusable chunk of schema declarations that can be used in several places, handy when you have multiple elements with similar structure. It might sometimes make sense to have a group with only one reference to it, but it can't make sense to have a group with no references to it.
Now there's an additional (and related) problem). Typically when you start validating an instance document, the validator looks for a global element declaration whose name matches the root element of the instance. But you don't have a global element declaration in your schema; your declaration of GENRELIST isn't global because it is in a group.

make axis2 to use specific return type

I am using an axis2 webservice, in which I am using following messageFormatter (org.apache.axis2.json.JSONMessageFormatter):
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
and following messageBuilder(org.apache.axis2.json.JSONOMBuilder):
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder"/>.
I have one element which I return as a String, Wsdl contract for which is as follows:
<xs:element minOccurs="0" name="totalCostStr" nillable="true" type="xs:String">
My problem here is when I receive the corresponding JSON and if totalCostStr is greater than 0.00, I am getting totalCostStr at client side in JSON as a string "0.00"
and when value totalCostStr is greater than 0, I get value at client side, in JSON as float (e.g. 12.65) and not as a string "12.65".
Is there a way to force axis to return totalCostStr as a Float or String always??
Thanks in advance,
Chetan
This is a strange behaviour :/
You can for to use always as float using the type float in wsdl element
<xs:element minOccurs="0" name="totalCostStr" nillable="true" type="xs:float"/>
This should work...

request generation in vb.net soap client

Take the tripservice wsdl from this link In this wsdl, I replaced the from element with the below(added nillable as true and added min length and max length restriction).
<xs:element minOccurs="0" name="from" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Now in my vb.net client i invoked the service by adding service reference, wsdl saved to a local folder.
Dim objproxy As New Tripservice.TripPriceServiceFacadeClient
Dim gh As New Tripservice.trip
gh.adults = 9
gh.duration = 8
gh.rooms = 8
gh.to = "p"
objproxy.getTripPrice(gh)
It will throw end point not found exception, however i am interested in the request xml that is going. I enabled the trace and found that the below request is generated.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getTripPrice xmlns="http://trip.price.service">
<trip xmlns="">
<adults>9</adults>
<duration>8</duration>
<from xsi:nil="true"/>
<rooms>8</rooms>
<to>p</to>
</trip>
</getTripPrice>
</s:Body>
</s:Envelope>
The element from xsi:nil="true" is generated, even though i am not touching the element in my vb.net code to generate the request. The element is optional as per the wsdl(min occurs = 0). How can i send a request without the from element name, even passed in the request?
You can't; it is interesting to find out why you changed it to nillable; in doing that, the way .NET code generation works, you leave it no way to know whether it should marshall the tag or not; typically, an optional string that is null is not marshalled. An optional (minOccurs=0) and nillable wouldn't work since there is no "set" indicator (JAXB has it or use to have it) to keep trace whether the user code set the value, null or not null.

why did not got any error while validating my xml?

My Xml is not getting correctly validated against the XSD.
I expect the browser to through atleast some kind of generic error messages when i open xml file
My Xml file is below
note.Xml
<?xml version="1.0"?>
<note
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="note.xsd">
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
My Xsd file is below
note.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified"><xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
<xs:attribute name="to" type="xs:string" use="required"/>
</xs:complexType>
</xs:element></xs:schema>
Both the note.xml and note.xsd files are in the same folder.
Can somebody guide why i am not getting any error? So Can anyone help me how to validate my xml file with xsd? Thank you,
Three problems:
xsi:schemaLocation attribute value
should be a white-space separate
sequence of namespace URI and schema
document URI, like xsi:schemaLocation="http://www.w3schools.com note.xsd"
You wrote:
I expect the browser to through
atleast some kind of generic error
It's not clear that you are actually
using some validation tool. No
browser validates XML Schema when
you open an XML document.
Your schema targets the
http://www.w3schools.com namespace
URI, but your document is under null
(or empty) namespace URI. This will
end up in validation error, even if
you use the
xsi:noNamespaceSchemaLocation
instead of the xsi:schemaLocation
attribute. Maybe you want to add a
default namespace declaration in
your input source like
xmlns="http://www.w3schools.com"...

Can a WCF data contract be recursive? For example a binary tree? Is there a difference with ASMX services in supporting recursive data structures?

In SOA I believe that the wsdl does not support recursive data types but I saw some examples where the proxy actually works. Anybody knows more about this?
Recursive type definitions are allowed and even cyclic object graphs are allowed and serializable. However, in order to keep from running out of stack space while serializing and deserializing, you'll need to create a custom behavior overriding the CreateSerializer method and setting the preserveObjectReferences parameter to true when its creating a DataContractSerializer. See James Kovacs' blog for more.
Please define what you mean by recursive. The following is a valid XML Schema for use in a WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Node" type="NodeType"/>
<xs:complexType name="NodeType">
<xs:sequence>
<xs:element name="Node" type="NodeType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>