尝试添加&
为元素值之一,但StreamMarkupBuilder
无法识别&
或&
代码为
def buildXml {
def requestXml = {
RootElement {
Element1("&Value1")
Element2("Value2")
}
}
return new StreamingMarkupBuilder().bind(requestXml)
}
输出是
<RootElement>
<Element1>&Value1</Element1>
<Element2>Value2</Element2>
</RootElement>
预期产出
<RootElement>
<Element1>&Value1</Element1>
<Element2>Value2</Element2>
</RootElement>
我遇到了MarkupBuilder
的setEscapeAttributes()
方法。医生说
Defaults to true. If set to false then you must escape any special characters within attribute values such as '&', '<', CR/LF, single and double quotes etc. manually as needed. The builder will not guard against producing invalid XML when in this mode and the output may not be able to be parsed/round-tripped but it does give you full control when producing for instance HTML output.
寻找类似的东西StreamMarkupBuilder