【发布时间】:2014-12-18 19:22:18
【问题描述】:
我需要在我的一些 XML 节点中嵌入一些 HTML,而消费者希望它在 CDATA 部分中。他们希望将 CDATA 保留为<![CDATA[ ]]>.,但开始和结束尖括号被转义,因此他们收到的是&lt;![CDATA[]]&gt;。我尝试了许多不同的方法,但似乎没有任何效果。 Restlet 框架中似乎没有内置任何功能。有没有其他人遇到过这个问题并找到了解决方案?这是我的代码示例:
@Get
public Representation toXml() {
// Create a new SAX representation
SaxRepresentation result = new SaxRepresentation() {
public void write(org.restlet.ext.xml.XmlWriter writer)
throws IOException {
...
try {
// Start document
writer.startDocument();
// Append the root node
writer.startElement(COMPANIES);
// I want to start the CDATA section here.
writer.startElement(BRANCHES);
if((mfgRepList != null) && (mfgRepList.size() > 0)){
writer = MfgRep.getMfgRepHtml(writer, mfgRepList);
}
writer.endElement(BRANCHES);
// I want to end the CDATA section here.
writer.endElement(COMPANIES);
writer.endDocument();
} catch (SAXException e) {
throw new IOException(e.getMessage());
}
}; // end of write
}; // end of create new Sax representation
return result;
}
【问题讨论】: