[英]How do I add !DOCTYPE to my html with groovy
I would like to add the following DOCTYPE to my html email with groovy. 我想使用groovy将以下DOCTYPE添加到我的html电子邮件中。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
My groovycode starts like this: 我的groovycode是这样开始的:
def responseDoc = job.addDocument("ECommerce_test.html"){out ->
def xmlWriter = new OutputStreamWriter(out)
MarkupBuilder html = new MarkupBuilder(xmlWriter)
I have tried to use the MarkupBuilderHelper, but I don' whant the xml-declaration. 我试图使用MarkupBuilderHelper,但我不希望xml声明。 This is the code I have used with MarkupBuilderHelper and it doesn't seems to work without the declaration.
这是我与MarkupBuilderHelper一起使用的代码,如果没有声明,它似乎无法工作。
def helper = new groovy.xml.MarkupBuilderHelper(xml)
helper.xmlDeclaration([version:'1.0', encoding:'UTF-8', standalone:'no'])
helper.yieldUnescaped """<!DOCTYPE note SYSTEM "note.dtd">"""
/Therese /泰蕾兹
Something like this with StreamingMarkupBuilder? StreamingMarkupBuilder这样的东西吗?
import groovy.xml.*
def responseDoc = job.addDocument("ECommerce_test.html"){out ->
out << new StreamingMarkupBuilder().bind {
mkp.yieldUnescaped '<?xml version="1.0", encoding="UTF-8", standalone="no"?>\n'
mkp.yieldUnescaped '<!DOCTYPE note SYSTEM "note.dtd">\n'
html {
body {
h1('WOW!')
}
}
}
}
An alternaive: 一个替代方案:
import groovy.xml.*
job.addDocument("ECommerce_test.html"){out ->
new StringWriter().with { sw ->
new MarkupBuilder(sw).html {
body {
h1('WOW!')
}
}
out << '<!DOCTYPE note SYSTEM "note.dtd">\n' << sw.toString()
}
}
It does look like a bug. 它看起来确实像个错误。
yieldUnescaped
works within a closure (within a tag), or after xml declaration, but not for generating a first top level statement. yieldUnescaped
在闭包内(在标记内)或在xml声明之后工作,但不适用于生成第一个顶级语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.