繁体   English   中英

Castor 读取文本元素的属性

[英]Castor read an attribute of a text element

我想知道如何使用脚轮映射(版本 0.9.9.1)进行 map。

<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>

我的 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”? 或者更好的是,如何将 map 转换为 class 属性?

谢谢你。

我找到了解决方案:

映射:

<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>

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;
    }
}

注意文本字段

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM