JavaでJerichoを使用してカスタムスタートタグを探すにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/3537355

  •  30-09-2019
  •  | 
  •  

質問

タイトルが言っているように、私は標準以外のstartTagtypeを形で一致させようとしています <foo:bar ...>

ジェリコでこれをどうやってやるの?

編集:

フォローカスタムStartTagTypeを作成しました:

PrimoResultStartTagType primoSTT = new PrimoResultStartTagType("search", "<sear:DOC", ">", EndTagType.NORMAL, false, true, true);

...と:

class PrimoResultStartTagType extends StartTagType {

    protected PrimoResultStartTagType(String arg0, String arg1, String arg2, EndTagType arg3, boolean arg4, boolean arg5, boolean arg6) {
        super(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
    }

    @Override
    protected Tag constructTagAt(Source arg0, int arg1) {
        return null;
    }

}

しかし、私がするとき source.getAllElements(...), 、私はマッチをしません。

役に立ちましたか?

解決

多分それは助けになるでしょう:

例HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>StartTagType (Jericho HTML Parser 3.1)</title>
</head>

<body>

<span>simple tag</span>

<test:name>custom tag</test:name>

</body>

</html>

サンプルコード:

public class Main {

public static void main(String[] args)
        throws IOException {

    URL url = Main.class.getClassLoader().getResource("test.html");
    Source source = new Source(url);
    List<Element> elementList = source.getAllElements("test:name");
    for (Element element : elementList) {
        System.out.println("Custom tag content: " + element.getContent().toString());
    }
}

}

出力:

Custom tag content: custom tag
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top