public class DocumentParser extends Parser
这将消息所有有效标记的回调以及隐含但未明确指定的标记。 例如,html字符串(<p> blah)只有定义了ap标签。 回调将看到以下方法:
Boolean.TRUE
,关键HTMLEditorKit.ParserCallback.IMPLIED
。
HTML.Attributes定义了html属性的类型安全枚举。 如果HTML.Attribute中定义了一个标签的属性键,则将使用HTML.Attribute作为键,否则将使用String。 例如<p foo = bar class = neat>有两个属性。 foo没有在HTML.Attribute中定义,因为它是Class,因此AttributeSet将有两个值,其中的值为“neat”的String.Attribute.CLASS和String值为'foo'的String key为'酒吧'。
position参数将指示标签,注释或文本的开始。 与数组类似,流中的第一个字符的位置为0.对于隐含的标记,位置将指示下一个遇到标记的位置。 在第一个示例中,隐含的起始正文和html标签将具有与p标记相同的位置,并且隐含的结尾p,html和body标签都将具有相同的位置。
当html跳过空格时,文本的位置将是第一个有效字符的位置,例如在字符串'\ n \ n \ nblah'中,文本“blah”将具有3的位置,跳过换行符。
对于没有值的属性,例如在html字符串<foo blah>
,属性blah
没有值,将有两个可能的值放在AttributeSet的值中:
HTML.NULL_ATTRIBUTE_VALUE
。
<!ATTLIST OPTION selected (selected) #IMPLIED>
将使用dtd(在这种情况下选择)中的此值。
一旦流已被解析,回调通知最可能的行字符串结束。 行字符串的结尾将是\ n,\ r或\ r \ n中的一个,这在解析流中遇到最多。
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
Constructor and Description |
---|
DocumentParser(DTD dtd)
|
Modifier and Type | Method and Description |
---|---|
protected void |
handleComment(char[] text)
遇到HTML注释时调用。
|
protected void |
handleEmptyTag(TagElement tag)
处理空标签。
|
protected void |
handleEndTag(TagElement tag)
处理结束标签
|
protected void |
handleError(int ln,
String errorMsg)
发生了错误。
|
protected void |
handleStartTag(TagElement tag)
处理起始标签。
|
protected void |
handleText(char[] data)
处理文本。
|
void |
parse(Reader in,
HTMLEditorKit.ParserCallback callback,
boolean ignoreCharSet)
|
endTag,
error,
error,
error,
error,
flushAttributes,
getAttributes,
getCurrentLine,
getCurrentPos,
handleEOFInComment,
handleTitle,
makeTag,
makeTag,
markFirstTime,
parse,
parseDTDMarkup,
parseMarkupDeclarations,
startTag
public DocumentParser(DTD dtd)
public void parse(Reader in, HTMLEditorKit.ParserCallback callback, boolean ignoreCharSet) throws IOException
IOException
protected void handleStartTag(TagElement tag)
handleStartTag
在
Parser
protected void handleComment(char[] text)
Parser
handleComment
在
Parser
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException
protected void handleEndTag(TagElement tag)
handleEndTag
在
Parser
protected void handleText(char[] data)
handleText
在
Parser
protected void handleError(int ln, String errorMsg)
Parser
handleError
在
Parser