Results 1 to 12 of 12
Thread: java wcf nodelist types
- 04-29-2012, 02:15 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
java wcf nodelist types
hi
im using this code to get my object from wcf :
Java Code:NodeList nodes =Tools.GetNodeList(MessageFormat.format(loginUrl,appLogin.GetKey(),appLogin.GetClientID(),profID),"/ArrayOfEvent/Event"); //(NodeList)xPath.evaluate("/ArrayOfEvent/Event",response,XPathConstants.NODESET); int nodeCount = nodes.getLength(); //iterate over search Result nodes XPathFactory factory = XPathFactory.newInstance(); XPath xPath=factory.newXPath(); for (int i = 0; i < nodeCount; i++) { String venue = xPath.evaluate("Venue", nodes.item(i)); Date startDate = Date.valueOf(xPath.evaluate("StartDate", nodes.item(i))); Date endDate = Date.valueOf(xPath.evaluate("EndDate", nodes.item(i))); Event ev = new Event(venue,startDate,endDate); list.add(ev); } } catch (Exception e) { e.printStackTrace(); }
2.i get exception when im getting to the Date parsing startDate and enddate
how can i get the date? thats example of the xml i get from wcf-rest:
Java Code:> <ArrayOfEvent> <Event> <CompanyName></CompanyName> <Description></Description> <EndDate>2012-05-08T00:00:00</EndDate> <Id>3954</Id> <Logo>3954.png</Logo> <Name>aaa2012</Name> <ShortEventName>Miltech</ShortEventName> <StartDate>2012-05-08T00:00:00</StartDate> <Subtitle i:nil="true"/> <Venue></Venue> </Event> </ArrayOfEvent>
- 04-29-2012, 03:13 PM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 301
- Rep Power
- 9
Re: java wcf nodelist types
IF you tell us _what_ exception (stack trace please!) you get one might help...
- 04-29-2012, 03:24 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
- 04-29-2012, 03:47 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
Re: java wcf nodelist types
ok now after i change it to :
Date startDate = (Date) new SimpleDateFormat().parse(xPath.evaluate("StartDate ", nodes.item(i)));
i got this error:
java.text.ParseException: Unparseable date: "2012-05-14T00:00:00"
-
Re: java wcf nodelist types
Read the SimpleDateFormat API. You're simply using it wrong.
- 04-29-2012, 04:29 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
Re: java wcf nodelist types
thanks.
this code is working :
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = formatter.parse(xPath.evaluate("StartDate", nodes.item(i)).replace("T"," "));
Date endDate = formatter.parse(xPath.evaluate("EndDate", nodes.item(i)).replace("T"," "));
is it correct writing?
- 04-29-2012, 04:54 PM #7
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 301
- Rep Power
- 9
Re: java wcf nodelist types
You do not even have to replace the "T" - just include it in the formatter's format string.
Here is more of the API : SimpleDateFormat (Java 2 Platform SE v1.4.2)
- 04-29-2012, 05:11 PM #8
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
Re: java wcf nodelist types
i did not find any format with T ,when i tried to add it to the format i got exception.
- 04-29-2012, 08:38 PM #9
Re: java wcf nodelist types
Please don't post links to old versions that have long been EOL. Bookmark these:
Java Platform SE 6
Java Platform SE 7
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-29-2012, 08:39 PM #10
Re: java wcf nodelist types
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-29-2012, 09:50 PM #11
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 301
- Rep Power
- 9
Re: java wcf nodelist types
I googled it and I did not care about the version to be honest. You are probably right - when I know which version he uses I do and it hasn't changed that much in usage anyway.
So here you go: SimpleDateFormat (Java Platform SE 7 )
EDIT: I use it with the "T" (included correctly) every day and it works for me, but maybe your timestamp or java version is another one.Last edited by Sierra; 04-29-2012 at 09:53 PM.
- 04-29-2012, 10:10 PM #12
Re: java wcf nodelist types
Sierra
The problem isn't about the specific class for which you posted an API link. Others who come across this thread may follow that link and then be unable to find another class or method that was introduced in a later version, leading to some confusion.
Google searches always push old API to the top, simply because the page hit count and search click-through count are obviously vastly higher than for the newer versions. I guess HTML could do with some sort of @Deprecated META tag :)
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
Java Data Types ?!
By HearT.Hunt3r in forum New To JavaReplies: 4Last Post: 08-09-2011, 05:43 PM -
Is it possible to use xpath with a Node or NodeList objects?
By omripe in forum XMLReplies: 6Last Post: 07-22-2011, 03:05 PM -
encryption types in java
By vasantharaman24@gmail.com in forum Suggestions & FeedbackReplies: 0Last Post: 10-22-2008, 03:55 PM -
How to get NodeList from XML file
By Java Tip in forum Java TipReplies: 0Last Post: 12-13-2007, 10:16 AM
Bookmarks