Hi
how do i convert a strnig to XMLGregorianCalendar type.

I used the below code for this but it throws an exception. userInput41 is a stirng parameter.

XMLGregorianCalendar sdate=DatatypeFactory.newInstance().newXMLGregorianCalendar(userInput41);

appreciate a reply
thanks

So what ex actly is the complete text of the exception? It should tell you exactly what went wrong and where. And what was the value of userInput41?
You are asking people to help, but you have not provided the info they need.

System.out.println("Enter End Date");
                    Scanner scanner42 = new Scanner(System.in);
                    String userInput42 = scanner42.nextLine();


                    Date edate=null;
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
                    sdate=df.parse(userInput41); 
                    edate=df.parse(userInput42);


                    GregorianCalendar cal2 = new GregorianCalendar();
                    cal1.setTime(sdate);
                    cal2.setTime(edate);
                                        XMLGregorianCalendar xmleDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH)+1, cal2.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED);

System.out.println(xmleDate);

///////////////////////////////////////////////////////////

@WebMethod(operationName = "GetHolidaysForDateRange", action = "http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForDateRange")
    @WebResult(name = "GetHolidaysForDateRangeResult", targetNamespace = "http://www.holidaywebservice.com/HolidayService_v2/")
    @RequestWrapper(localName = "GetHolidaysForDateRange", targetNamespace = "http://www.holidaywebservice.com/HolidayService_v2/", className = "HolidayClient2.GetHolidaysForDateRange")
    @ResponseWrapper(localName = "GetHolidaysForDateRangeResponse", targetNamespace = "http://www.holidaywebservice.com/HolidayService_v2/", className = "HolidayClient2.GetHolidaysForDateRangeResponse")
    public ArrayOfHoliday getHolidaysForDateRange(
        @WebParam(name = "countryCode", targetNamespace = "http://www.holidaywebservice.com/HolidayService_v2/")
        Country countryCode,
        @WebParam(name = "startDate", targetNamespace = "http://www.holidaywebservice.com/HolidayService_v2/")
        XMLGregorianCalendar startDate,
        @WebParam(name = "endDate", targetNamespace = "http://www.holidaywebservice.com/HolidayService_v2/")
        XMLGregorianCalendar endDate);

i got away with the exception now i am getting a different error
as below when sending the edate parameter to the

etHolidayForDateRange

System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 237). ---> System.FormatException: The string '' is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value)
at System.Xml.Serialization.XmlSerializationReader.ToDateTime(String value)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read17_GetHolidaysForDateRange()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer12.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

appreciate a reply
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.