Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: java wcf nodelist types

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java wcf nodelist types

    hi

    im using this code to get my object from wcf :

    NodeList nodes =Tools.GetNodeList(MessageFormat.format(loginUrl,appLogin.GetKey(),appLogin.GetClientID(),profID),"/ArrayOfEvent/Event");     
                    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(); 
        }

    1.i hope im doing it in the right way, if not please let me know
    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:

    <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>


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java wcf nodelist types

    Quote Originally Posted by royroy7 View Post
    hi
    for (int i = 0; i < nodeCount; i++) {
        // Problem might start from here, are they the real thing you are expecting to get?                 
         String venue = xPath.evaluate("Venue", nodes.item(i)); 
         Date startDate = Date.valueOf(xPath.evaluate("StartDate", nodes.item(i))); //line 1
         Date endDate = Date.valueOf(xPath.evaluate("EndDate", nodes.item(i)));     //line 2
         //    
         Event ev = new Event(venue,startDate,endDate);
         list.add(ev);
    }
    Correct me if I am wrong: You should getting an IllegalArgumentException.
    1. Think of this, when i=0, what string will you get from xPath.evaluate("StartDate", nodes.item(i))? And, what will you get when i=1?
    2. Is the string you get from xPath.evaluate("StartDate", nodes.item(i)) a valid JDBC date escape format (yyyy-mm-dd)?
    3. What will happen when you convert a Non Valid string in JDBC date escape format to a Date value?

    Break each line (line 1 & line 2) into two and print the string out before converting it to a Date value.
    eg.
    String sStartDate = xPath.evaluate("StartDate", nodes.item(i));
    System.out.println(sStartDate);

    Also check this out: The Java XPath API
    Last edited by SmokyBrain; April 30th, 2012 at 06:45 AM.

Similar Threads

  1. What are the 3 types of self-reference in JAVA
    By wholegrain in forum Java Theory & Questions
    Replies: 1
    Last Post: March 5th, 2012, 05:49 PM
  2. Primitive types
    By sudesh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 30th, 2012, 01:44 AM
  3. Enumerated Types
    By mushy in forum Object Oriented Programming
    Replies: 3
    Last Post: January 27th, 2011, 10:06 AM
  4. incompatible types
    By frozen java in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2011, 10:40 AM
  5. Incompatible Types
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2010, 10:52 AM

Tags for this Thread