現在、Java XPath APIを使用して文字列からテキストを抽出しています。Java XPath APIテキストからHTMLタグを取り除く
しかし、この文字列は多くの場合、HTML形式(<b>
,<em>
、<sub>
など)です。コードを実行すると、HTMLタグが削除されます。これを避ける方法はありますか?ここで
は、サンプル入力である:ここで
<document>
<summary>
The <b>dog</b> jumped over the fence.
</summary>
</document>
は、私のコードの抜粋である:ここで
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
InputSource source = new InputSource(new StringReader(xml));
String output = xPath.evaluate("/document/summary", source);
は、現在出力されます。ここでは
The dog jumped over the fence.
は出力Iです欲しいもの:
The <b>dog</b> jumped over the fence.
ご協力いただきありがとうございます。
メソッドxPathの値を増やすことはできますか。評価する(文字列、var)ですか?たとえば、xPathのドット演算子を見て、太字のテキストを避けることができるかどうかを確認します。 – ElementCR