You are right Wing. Thats exactly the problem :) The actual service doesnt use
the xsd.
I did think about making it as type xs:string and then check for null but
wanted to keep ints as int (Though I agree I can apply a numeric restriction to
a string via xsd). Again everytime I will have to use Integer.parse operation.
I thought of adding a small method
public static boolean isXmlIntNull(XmlInt xmlInt) {
if(xmlInt == null || xmlInt.xmlText().equals("<xml-fragment/>")) {
return true;
}
return false;
}
And call it from the service code like
if(!XmlUtils.isXmlIntNull(item.xgetFileId()))
{
// We only get here if <file_id> has some value!
}
the xgetFileId() actually returns a xml-fragment and am checking against that.
I now call the method wherever we have that file_id thing... actually its not
only file_id - quite a few other fields have the same problem.
Thanks all for your inputs.
Regards,
SSP
________________________________
From: Wing Yew Poon <[email protected]>
To: [email protected]
Sent: Wed, 24 March, 2010 6:01:23 PM
Subject: RE: Xmlbeans errors for empty int tag
Of course, then you do have the inconvenience of having to
convert the file_id string to and from an int value, if indeed you are working
with ints, but that is the tradeoff.
________________________________
From: Wing Yew Poon
Sent: Wednesday,
March 24, 2010 10:50 AM
To: [email protected]
Subject: RE: Xmlbeans errors for empty int
tag
Making file_id nillable in the schema does not help since
the web service is still going to output <file_id/>, not <file_id
xsi:nil="true"/>. (The web service does not follow the schema, the schema is
only for generating XMLBeans, if I understood correctly.) I think file_id
should
not be of type xs:int, since <file_id/> is a possible output; why don't
you simply make the type xs:string, and then getFileId will return a String and
you can simply test if it is equal to "". I think that would be the simplest
solution.
- Wing Yew
________________________________
From: Soumya [mailto:[email protected]]
Sent: Wednesday, March 24, 2010 4:05 AM
To: [email protected]
Subject: Re: Xmlbeans errors for empty int
tag
Hi Jacob,
Yes I tried configuring it as nillable="true"
today.
And I tried to check
if(item.xgetFileId()!=null &&
item.xgetFileId().isNil())
{
///
}
But once again the isNil()
now threw the
error
org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException
at
org.apache.xmlbeans.impl.values.JavaIntHolder.set_text(JavaIntHolder.java:42)
at
org.apache.xmlbeans.impl.values.XmlObjectBase.update_from_wscanon_text(XmlObjectBase.java:1085)
at
org.apache.xmlbeans.impl.values.XmlObjectBase.check_dated(XmlObjectBase.java:1224)
at
org.apache.xmlbeans.impl.values.XmlObjectBase.isNil(XmlObjectBase.java:575)
Any
more suggestions friends?
Regards,
SSP
________________________________
From: Jacob Danner
<[email protected]>
To: [email protected]
Sent: Tue, 23 March, 2010 6:39:42
PM
Subject: Re: Xmlbeans errors
for empty int tag
have you tried adding nillable="true" to the
file_id element. I
believe this makes the type the Java Wrapper type (Integer
in this
case).
Otherwise to check the existence of the element you could
try xpath,
or using the xmlcursor apis and seeing if you can navigate to
the
element.
HTH,
-jacobd
On Tue, Mar 23, 2010 at 10:32 AM,
Soumya <[email protected]>
wrote:
> Hello all,
>
> I am using xmlbeans 1.0.4 and have a
strange issue at hand.
> We have an old webservice which was documented in
DTD and to use advanced
> xmlbeans features we decided to write an xsd for
it and use it at another
> place to send/get WS calls. Kindly note the xsd
is used only at client
> side..ie.e where it invokes the WS. The WS is
still the old one.
> Here is a snippet of teh xsd that is causing the
issue -
> <xs:complexType name ="itemT">
>
<xs:sequence maxOccurs="1">
>
<xs:element name="item_id" type="xs:int" minOccurs="1"
>
maxOccurs="1"/>
>
<xs:element name="file_id"
type="xs:int" minOccurs="0"
> maxOccurs="1"/>
>
.......................................
>
............</xs:sequence>
> </xs:complexType>
>
>
Now the 'file_id' field above is not mandatory and may be blank. The way
our
> old WS responds in case there is nor file_id associated with type
itemT is
> as follows.
> <item>
>
<item_id>1602</item_id>
>
<file_id/>
>
..........................
>
</item>
> SO even if there is no value for file_id it still returns
an empty tag.
>
> Now this is of type xs:int I cannot do a null
check - Hence in my java code
> whenever I try to access it
>
like
> item.getFileId() - It always throws an exception stacktrace as
follows
>
>
org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException
>
at
>
org.apache.xmlbeans.impl.values.JavaIntHolder.set_text(JavaIntHolder.java:42)
>
at
>
org.apache.xmlbeans.impl.values.XmlObjectBase.update_from_wscanon_text(XmlObjectBase.java:1085)
>
at
>
org.apache.xmlbeans.impl.values.XmlObjectBase.check_dated(XmlObjectBase.java:1224)
>
at
>
org.apache.xmlbeans.impl.values.JavaIntHolder.intValue(JavaIntHolder.java:52)
>
at
>
org.apache.xmlbeans.impl.values.XmlObjectBase.getIntValue(XmlObjectBase.java:1442)
>
at
com.company.webservices.live.impl.ItemTImpl.getFileId(Unknown Source)
>
at
>
com.company.live.ws.service.NewWebService.fetchItem(LiveWebService.java:150)
>
>
>
Is there a way in xmlbeans by which I can check that whether a "int
value"
> is present or not (like we do for String i.e. null check) and
only then try
> to retrieve the fileId value?
>
> I tried
using item.isSetFileId() but that returns as true.
>
> I also tried
item.xgetFileId() - checked if that is null but again when we
> try to get
intValue() it throws same exception.
>
> Can anyone kindly
help?
>
> Thanks in advance,
> SSP
>
>
________________________________
> Your Mail works best with the New Yahoo
Optimized IE8. Get it
NOW!.
---------------------------------------------------------------------
To
unsubscribe, e-mail: [email protected]
For
additional commands, e-mail: [email protected]
________________________________
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
http://in.yahoo.com/