1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cybernekoを使ってなるべく原型を留めてHTMLをDOMにパースするときのメモ

Posted at

大文字小文字なども原型を留めたい場合は色々設定が必要。

html2dom.java
// DOMパーサーはxercesを使う
DOMParser parser = new DOMParser(new HTMLConfiguration());
parser.setFeature("http://cyberneko.org/html/features/balance-tags", false);
parser.setFeature("http://cyberneko.org/html/features/balance-tags/document-fragment", true);				parser.setFeature("http://cyberneko.org/html/features/balance-tags/ignore-outside-content", true);parser.setFeature("http://cyberneko.org/html/features/scanner/notify-builtin-refs", true);
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "match");
parser.setProperty("http://cyberneko.org/html/properties/names/attrs", "no-change");
parser.setProperty("http://cyberneko.org/html/properties/default-encoding",	"UTF-8");
parser.parse(new InputSource(new StringReader(layout)));
Document doc = parser.getDocument();
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?