java - Castor 读取文本元素的属性
问题描述
我想知道如何使用脚轮映射(版本 0.9.9.1)来映射它。
<Classifica>
<Livello nome="812">1</Livello>
</Classifica>
我需要的是nome属性的值。
我试过这个:
<class name="it.ClassificaIDT" auto-complete="true">
<map-to xml="Classifica"/>
<field name="livello"
type="it.LivelloIDT"
container="false">
<bind-xml name="Livello"/>
</field>
</class>
<class name="it.LivelloIDT" auto-complete="true">
<map-to xml="Livello"/>
<field name="nome">
<bind-xml name="nome" node="attribute"/>
</field>
</class>
我的课是:
package it;
public class ClassificaIDT {
private LivelloIDT livello;
public LivelloIDT getLivello() {
return livello;
}
public void setLivello(LivelloIDT livello) {
this.livello = livello;
}
}
上面给出了这个错误:
Caused by: Illegal Text data found as child of: Livello
value: "1"{file: [not available]; line: 42; column: 56}
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:671)
at it.bz.prov.egov.foundation.fascicoloinformatico.service.eprocs.XMLConverter.createOutputForEProcsWebService(XMLConverter.java:121)
... 148 more
Caused by: org.xml.sax.SAXException: Illegal Text data found as child of: Livello
value: "1"
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:889)
如何忽略值“1”?或者更好的是,如何将其映射到类属性?
谢谢你。
解决方案
我找到了解决方案:
映射:
<class name="it.LivelloIDT" auto-complete="true">
<map-to xml="Livello"/>
<field name="nome" type="java.lang.String" get-method="getNome" set-method="setNome">
<bind-xml name="nome" node="attribute"/>
</field>
<field name="text" type="java.lang.String">
<bind-xml node="text" />
</field> </class>
班级:
public class LivelloIDT {
private String nome;
private String text;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
注意文本字段
推荐阅读
- angular - 将代码从 ChangeDetectionStrategy.Default 重构为 ChangeDetectionStrategy.OnPush
- postgresql - json 类型的 Postgres 无效输入语法详细信息:令牌“%”无效
- sorting - 在 Vala 中对默认数组进行排序的简单方法
- apache - 如何自动检测强制门户
- python - 具有自定义值权重的 pandas 中的虚拟编码
- terraform - 指定模块时,terraform init 不起作用
- javascript - Java有join方法,NodeJs有什么节点相当于它?
- python - 将第二个参数传递给 pool.map 中的函数
- wpf - WPF:具有多属性条件的 DataTrigger
- angular - 记住 Angular 5 中的选定选项卡(引导选项卡集)