Menu

#6 A number in the tag is not allowed

open-fixed
XPath (4)
5
2004-04-25
2004-04-13
Anonymous
No

When I try to use the XPathAPI I can't use a tag with a
number in it.
For example the tag: <Mededeling2> would not work,
because I got the exception:
com.hp.hpl.sparta.xpath.XPathException: Mededeling2 at
end of XPATH expression got "2<end of expression>"
instead of expected end of expression

Discussion

  • Eamonn O'Brien-Strain

    Logged In: YES
    user_id=266403

    This was fixed some time ago. To verify I added the following
    JUNIT test to the regression tests:

    /** Test for number in tag. */
    public void testBug934193() throws ParseException,
    IOException {
    String x = "<Mededeling2><Foo/></Mededeling2>";
    Document doc = Parser.parse(x);
    Element foo = doc.xpathSelectElement
    ("/Mededeling2/Foo");
    assertEquals(new Element("Foo"), foo);
    }

     
  • Eamonn O'Brien-Strain

    • status: open --> open-fixed
     
  • Nobody/Anonymous

    Logged In: NO

    This still didn't work for me using the 20031101 release. I
    made a small hack to XPath.java, adding
    <code>toks.wordChars('0','9');</code> at line 54. Not the
    correct answer I know, but it makes my app function.

     
  • Flávio Etrusco

    Flávio Etrusco - 2006-11-03

    Logged In: YES
    user_id=99702

    FWIW, it's fixed only in CVS and only the experimental(?)
    module 'sparta5'.
    The correct fix is to modify SimpleStringTokenizer.nextToken():
    (aprox. on 20th line, the 'else' statement inside
    'while..do' should be changed to:)

    else
    {
    currentType = charType_[ch];
    // -----> This is the fix.
    //after the first character there can be numbers in a word
    if (currentType == TT_NUMBER && ttype == TT_WORD)
    currentType = TT_WORD;
    // <-----
    }

     

Log in to post a comment.