Java 避免apacheabdera中的字符编码

Java 避免apacheabdera中的字符编码,java,atom-feed,apache-abdera,Java,Atom Feed,Apache Abdera,我正在编写一个简单的文章编辑器,它将与CMS系统一起使用,CMS系统提供一个AtomAPI来添加/编辑文章。为了与CMS通信,我使用ApacheAbdera库。但是我遇到了字符编码的问题。发送到CMS的数据编码如下: div xmlns=”http://www.w3.org/1999/xhtml“>p>文本在此显示/p>/div> 但CMS系统要求: 这里有文字 换句话说,没有字符转义。有人知道如何使用ApacheAbdera实现这一点吗?我对Abdera的内部结构并不完全熟悉,因此无法

我正在编写一个简单的文章编辑器,它将与CMS系统一起使用,CMS系统提供一个AtomAPI来添加/编辑文章。为了与CMS通信,我使用ApacheAbdera库。但是我遇到了字符编码的问题。发送到CMS的数据编码如下:


div xmlns=”http://www.w3.org/1999/xhtml“>p>文本在此显示/p>/div>
但CMS系统要求:


这里有文字


换句话说,没有字符转义。有人知道如何使用ApacheAbdera实现这一点吗?

我对Abdera的内部结构并不完全熟悉,因此无法准确解释这里发生了什么,但我认为其本质是,如果不希望Abdera逃避内容,就不能使用字符串或纯文本作为值。相反,您必须将
元素
与abdera类型
XHtml
一起使用

像这样的事情对我很有用:

String body = "<p>Text comes here</p>"

//put the text into an XHtml-Element (more specificly an instance of Div)
//I "misuse" a Content object here, because Content offers type=XHtml. Maybe there are better ways.
Element el = abdera.getFactory().newContent(Content.Type.XHTML).setValue(body).getValueElement();

//now create your empty <vdf:value/> node.
QName valueQName = new QName("http://your-vdf-namespace", "value", "vdf");
ExtensibleElement bodyValue = new ExtensibleElementWrapper(abdera.getFactory(),valueQName);

//now attach the Div to that empty node. Not sure what's happening here internally, but this worked for me :)
bodyValue.addExtension(el);
String body=“文本在此出现

” //将文本放入XHtml元素(更具体地说是Div的实例) //我在这里“误用”了内容对象,因为内容提供type=XHtml。也许有更好的方法。 元素el=abdera.getFactory().newContent(Content.Type.XHTML).setValue(body.getValueElement(); //现在创建空节点。 QName值QName=新的QName(“http://your-vdf-namespace“价值”、“vdf”); ExtensibleElement bodyValue=新的ExtensibleElementWrapper(abdera.getFactory(),valueQName); //现在将Div附加到该空节点。不确定这里内部发生了什么,但这对我来说很有效:) bodyValue.addExtension(el);
现在,
bodyValue
可以用作字段的值,Abdera应该正确渲染所有内容