【发布时间】:2011-12-16 19:33:37
【问题描述】:
我正在制作一个 HTML 渲染器。我将 html 文件读入 StreamTokenizer。目前它打印出正确的标记,并在我的 html 文件中指定我的变量,用美元括起来,例如
<html><p>$myVarToBeRendered$<p></html>
我得到了正确的标记,即它使用 quoteChar('$') 分割了 html 正文和 vars
FileReader in = new FileReader(file);
BufferedReader reader = new BufferedReader(in);
StreamTokenizer tok;
tok = new StreamTokenizer(reader);
tok.resetSyntax();
tok.wordChars(0, 255);
tok.quoteChar('$');
我得到了字符串标记
"<html><p>" , "myVarToBeRendered" and "<p></html>"
虽然在阅读令牌时,我显然需要替换标识为引号的 myVar 令牌。此 myVar 用作 HashMap 中的键,用于保存要呈现给每个变量的字符串值。有没有办法检查令牌是否是报价?喜欢:
if (tok.next - is a quote or inside my quotes)
Then replace this var name with its related HashMap value
我搜索了互联网,找不到任何示例或类似问题来帮助我!
或者我可以使用的任何方法,以便我可以识别哪些标记是要在 HashMap 中使用的变量。对不起,如果这没有意义,希望你明白我在做什么!
非常感谢山姆
【问题讨论】:
标签: java html regex rendering html-parsing