public class Parser extends Object implements DTDConstants
不幸的是,有许多好实现HTML解析器那里,因此有许多严重格式化的HTML文件。这个解析器试图解析多数HTML文件。这意味着实施有时偏离支持HTML的SGML规范。
解析器把R与\r\n \ n换行后starttags之前结束标记被忽略,正如在SGML和HTML规范规定。
HTML规范没有指定的空间都是很好的融合。具体来说,下面的场景没有讨论(请注意这里使用的空间,但我使用的是要显示的空间):
“等等 <罢工> foo”可被视为:“ 等等 <罢工> foo 罢工> 罢工>
以及:“
< a href =“XX”> < EM >用< / EM >
如果strict
是虚假的,当一个标签,打破流,(TagElement.breaksFlows
)或尾随空格时,所有的空格将被忽略,直到遇到一个非空白字符。这似乎给了更接近流行的浏览器的行为。
DTD
,
TagElement
,
SimpleAttributeSet
Modifier and Type | Field and Description |
---|---|
protected DTD |
dtd |
protected boolean |
strict
这个标志决定是否执行SGML解析器将兼容性要求严格。
|
ANY, CDATA, CONREF, CURRENT, DEFAULT, EMPTY, ENDTAG, ENTITIES, ENTITY, FIXED, GENERAL, ID, IDREF, IDREFS, IMPLIED, MD, MODEL, MS, NAME, NAMES, NMTOKEN, NMTOKENS, NOTATION, NUMBER, NUMBERS, NUTOKEN, NUTOKENS, PARAMETER, PI, PUBLIC, RCDATA, REQUIRED, SDATA, STARTTAG, SYSTEM
Modifier and Type | Method and Description |
---|---|
protected void |
endTag(boolean omitted)
处理结束标签。
|
protected void |
error(String err) |
protected void |
error(String err, String arg1) |
protected void |
error(String err, String arg1, String arg2) |
protected void |
error(String err, String arg1, String arg2, String arg3)
调用错误处理程序。
|
protected void |
flushAttributes() |
protected SimpleAttributeSet |
getAttributes() |
protected int |
getCurrentLine() |
protected int |
getCurrentPos() |
protected void |
handleComment(char[] text)
当一个HTML注释时。
|
protected void |
handleEmptyTag(TagElement tag)
遇到一个空标记时调用。
|
protected void |
handleEndTag(TagElement tag)
当遇到一个结束标记时调用。
|
protected void |
handleEOFInComment() |
protected void |
handleError(int ln, String msg)
发生了一个错误。
|
protected void |
handleStartTag(TagElement tag)
当遇到一个开始标记时调用。
|
protected void |
handleText(char[] text)
打电话时遇到85。
|
protected void |
handleTitle(char[] text)
当一个HTML标题标签是遇到。
|
protected TagElement |
makeTag(Element elem) |
protected TagElement |
makeTag(Element elem, boolean fictional)
让tagelement。
|
protected void |
markFirstTime(Element elem)
标记在文档中被看到的第一个标签
|
void |
parse(Reader in)
解析HTML流,给定一个DTD。
|
String |
parseDTDMarkup()
分析了文档声明式标记声明。
|
protected boolean |
parseMarkupDeclarations(StringBuffer strBuff)
解析标记声明。
|
protected void |
startTag(TagElement tag)
处理开始标签。
|
protected DTD dtd
protected boolean strict
public Parser(DTD dtd)
protected int getCurrentLine()
protected TagElement makeTag(Element elem, boolean fictional)
protected TagElement makeTag(Element elem)
protected SimpleAttributeSet getAttributes()
protected void flushAttributes()
protected void handleText(char[] text)
protected void handleTitle(char[] text)
protected void handleComment(char[] text)
protected void handleEOFInComment()
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException
protected void handleStartTag(TagElement tag)
protected void handleEndTag(TagElement tag)
protected void handleError(int ln, String msg)
protected void error(String err)
protected void startTag(TagElement tag) throws ChangedCharSetException
protected void endTag(boolean omitted)
protected void markFirstTime(Element elem)
public String parseDTDMarkup() throws IOException
IOException
protected boolean parseMarkupDeclarations(StringBuffer strBuff) throws IOException
IOException
public void parse(Reader in) throws IOException
IOException
protected int getCurrentPos()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.