技术标签: java. jaxb. XML序列化 编组 HTML实体
I have an Object that is being marshalled to XML using JAXB. One element contains a String that includes quotes ("). The resulting XML has " where the " existed.
Even though this is normally preferred, I need my output to match a 遗产 系统。 How do I force JAXB to NOT convert the HTML entities?
--
感谢您的答复。 However, I never see the handler escape() called. Can you take a look and see what I'm doing wrong?谢谢!
package org.dc.model;
import java.io.IOException;
import java.io.Writer;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.dc.generated.Shiporder;
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler;
public class PleaseWork {
public void prettyPlease() throws JAXBException {
Shiporder shipOrder = new Shiporder();
shipOrder.setOrderid("Order's ID");
shipOrder.setOrderperson("The woman said, \"How ya doin & stuff?\"");
JAXBContext context = JAXBContext.newInstance("org.dc.generated");
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(CharacterEscapeHandler.class.getName(),
new CharacterEscapeHandler() {
@Override
public void escape(char[] ch, int start, int length,
boolean isAttVal, Writer out) throws IOException {
out.write("Called escape for characters = " + ch.toString());
}
});
marshaller.marshal(shipOrder, System.out);
}
public static void main(String[] args) throws Exception {
new PleaseWork().prettyPlease();
}
}
--
The output is this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<shiporder orderid="Order's ID">
<orderperson>The woman said, "How ya doin & stuff?"</orderperson>
</shiporder>
and as you can see, the callback is never displayed. (Once I get the callback being called, I'll worry about having it actually do what I want.)
--
Solution my teammate found:
PrintWriter printWriter = new PrintWriter(new FileWriter(xmlFile));
DataWriter dataWriter = new DataWriter(printWriter, "UTF-8", DumbEscapeHandler.theInstance);
marshaller.marshal(request, dataWriter);
Instead of passing the xmlFile to marshal(), pass the DataWriter which knows both the encoding and an appropriate escape handler, if any.
Note: Since DataWriter and DumbEscapeHandler are both within the com.sun.xml.internal.bind.marshaller package, you must bootstrap javac.
could not convert string to float(KNN) 出现这种情况,是txt里面的空格个数和\t的空格个数差异导致的,对此只需要复制txt里面的空格,粘贴到\t原来的位置。 然后代码就快乐的跑起来咯 代码来自:https://www.cnblogs.com/further-further-further/p/9670187.html...
在连接本机的mysql 数据库时,配置连接信息,连接发生错误,提示:message from server: "Host 'DESKTOP-4OMV7N8' is not allowed to connect to this MySQL server 但是将IP地址改为localhost又能正常连接到MySQL数据库。 临时处理方案: 1、先用localhost方式连接到MySQL数据库...
转载自: http://hyperparameter.space/blog/when-not-to-use-deep-learning/ I know it’s a weird way to start a blog with a negative, but there was a wave of discussion in the last few days that I think...
typeError: Can’t convert ‘tuple’ object to str implicitly 不能隐式的自动将tuple类型转换成str 我遇到这个问题是因为调用函数里面添加了两个字符串相加的操作。 但是由于粗心,字符串定义后面添加了一个逗号,直接导致str类型转变成了tuple类型。这个操作根据调用函数的不同,会出现不同的错误信息,下面这...
前几天写Java,因为是初学者,用的Eclipse,出现报错:Type dismatch,cannot convert from java.lang.String to String,我还以为是Eclipse的配置出了问题,因为问题确实比较简单,网上找不到答案,百思不得其解,本来想问别人的,后来想想还是锻炼一下自己解决问题的能力,搞了半天,终于搞懂了, 类名用了保留字String,改成String...
Android软件开发之在程序中时时获取logcat日志信息 雨松MOMO原创文章如转载,请注明:转载自雨松MOMO的博客原文地址:http://blog.csdn.net/xys289187120/article/details/6765046 各位大小盆友们晚上好,由于这周在公司连续加了5天通宵班,项目实在太紧了。还好MOMO没有挂到公司顺利的回到了温暖的家嘎嘎。不过MOMO还是不忘大伙们 哇...
1.我们可以使用 docker build 来创建一个新的镜像。为此,首先需要创建一个 Dockerfile,包含一些如何创建镜像的指令,新建一个目录和一个 Dockerfile 2.Dockerfile 中每一条指令都创建镜像的一层,例如: Dockerfile 基本的语法是:使用 # 来注释 :FROM 指令告诉 Docker 使用哪个镜像作为基础 ,接着是维护者...
这个工具用来将创建Oracle属性表的SQL语句转换为Excel文档,继而可以将Excel的内容复制到word文档中,实现快速编写数据库说明和数据库设计文档的辅助工具。 我们来看一下效果: 运行程序: 转换成的XLS文件: 剪切到Word中的效果: 工具和代码的下载地址: 在我的资源页。http://download.csdn.net/detail/lllzd/4522271...
索引组织表 在InnoDB存储引擎中,表都是根据主键顺序组织存放的,这种存储方式的表称为索引组织表。如果创建时没有显式的定义主键,那么会有两种策略进行主键的建立。 首先判断表中是否有非空唯一索引,如果有,则该列为主键。如果有多个,则按照顺序选择第一个为主键,该处的顺序指定义索引时的顺序而不是建表时的顺序。联合索引则不会被选为主键。 如果不符合条件1,InnoDB自动创建一个6字节大小的指针。 查询...
记大三中遇到的一些迷茫 生活不是一帆风顺,应当是有起有落,没有伞的孩子,就努力在雨中奔跑吧!相信经历风雨的磨砺,一路上感受到不一样的景色,会变得更加坚强,成为更好的自己~~ 在大二升大三的时候,我记得在暑假期间,给老师发了短信(大二的时候,老师还是比较关注我的,毕竟那时候能力比较好一些),信中是希望老师能够在大三的时候,看能不...
I am developing an iOS app with Cordova and I am using the Facebook-connect plugin for authentification. My problem : sometimes the Facebook Plugin doesn't load early enough so the FB authentification...
I try to run rails application (Rails 4.2.0) in production mode with these settings: config/environment/production.rb config/initializer/assets.rb app/assets/application.js app/assets/photos.js I expe...
Hello i just started learning Jquery and my below code is not working and its not even showing any error in console. The above script is not doing anything when i focus the input box. The same code is...
This path will must be localhost:8080/hotel/:id (id = json.hoteID) Egg: localhost:8080/hotel/101 and this path must show me own datas We should use VueJS vue-router...
I have a struct with two pointers and an int variable. For some reason I am getting a segmentation fault at the line ptr->i=0;. Why is that? I'm pointing to something in the memory, i is not a poin...