Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lxml alternative in Java?

Tags:

java

python

lxml

I have been extensively using lxml for developing algos. But now, due to performance issues, I have to migrate to Java. Moral is, can I find as awesome as lxml dom parser in Java?

> Key requirements :

1) feature like text_content() 2) iterchildren and 3) iterparent() and itersiblings()--- (if xpath is there, I think we can do such traversing, not sure).

Jsoup is famous there, but not sure if all can be done. I just want to port algorithms not heavy rewriting. Please suggest.

Thanks.

Why Java : I am doing complex nlp and dom parsing tasks. Python is first choice and will remain.Writing c-extension is one thing, and performing complex nlp tasks is another, and merging two is yet another thing. Hence Java. Nothing offensive.

like image 345
akshayb Avatar asked Aug 12 '26 22:08

akshayb


1 Answers

Saxon is your best bet in my opinion http://saxon.sourceforge.net . A bunch of examples can be found in this download of saxon-resources9-4.zip found here: http://sourceforge.net/projects/saxon/files/Saxon-HE/9.4/ like xpath expressions:

    XPathExpression findLine =
        xpe.compile("//LINE[contains(., $word)]");
    XPathExpression findLocation =
        xpe.compile("concat(ancestor::ACT/TITLE, ' ', ancestor::SCENE/TITLE)");
    XPathExpression findSpeaker =
        xpe.compile("string(ancestor::SPEECH/SPEAKER[1])");
like image 186
rainkinz Avatar answered Aug 15 '26 13:08

rainkinz