SimpleDateFormat with Node.getNodeValue

Discussion in 'Java' started by Manuel, Aug 28, 2003.

  1. Manuel

    Manuel Guest

    Hi all.

    I have the strangest problem. When I run this test-program, all runs fine:

    public static void main(String[] args) {
    Date d = null;
    try{
    SimpleDateFormat sdf = new SimpleDateFormat( "MMM-dd HH:mm" );
    d = sdf.parse( "Aug-26 20:15");
    System.out.println( "Date is valid: " + d.toString() );
    } catch( ParseException pe ){
    pe.printStackTrace();
    }
    }

    BUT: when I try to do the same thing using the string returned from
    a DOM-Node (getNodeValue()), I get a ParseException...


    private boolean collectDate( Node cell ){
    if( cell == null )return false;
    Node child = cell.getFirstChild();
    if( child == null )return false;
    String childName = child.getNodeName();
    if( !childName.equals( "#text") ){
    return collectDate( child );
    }
    String str = child.getNodeValue();
    SimpleDateFormat sdf = new SimpleDateFormat( "MMM-dd HH:mm" );
    Date d = null;
    try{
    d = sdf.parse( str );
    DoSomething.with( d );
    } catch ( ParseException pe ){
    Log.error( "Could not parse date '" + str + "'" );
    Log.error( pe );
    return false;
    }
    }

    Any ideas what could be going on?
    Thank you very much.
    Manoo
     
    Manuel, Aug 28, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,671
  2. Peter Chatterton

    DOM Problem with getNodeValue()

    Peter Chatterton, Oct 19, 2003, in forum: Java
    Replies:
    9
    Views:
    2,856
    Peter Chatterton
    Oct 20, 2003
  3. David
    Replies:
    4
    Views:
    3,939
    Toni Uusitalo
    Dec 17, 2003
  4. Bernard Kufluk

    problem with getNodeValue

    Bernard Kufluk, Apr 21, 2004, in forum: XML
    Replies:
    1
    Views:
    524
    Bernard Kufluk
    Apr 21, 2004
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,521
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page