简体   繁体   English

如何使用Digester将XML解析为Java对象

[英]How to parse XML to Java object with Digester

I am using apache Digester parse XML to object. 我正在使用apache Digester解析XML来对象。 I have the following XML element: 我有以下XML元素:

<a type="X" xname = "...">..<a>
<a type="T" tname = "...">..<a>

I have class 我有课

public class X{
  private String xname;
  public static class T{
     private String tname;
  }

}

Is it able to if the type is X then I create class X, if type is T then create class T, notice T is public inner and child class of X. if yes, how to define the rule. 如果类型是X,那么我可以创建类X,如果类型是T,然后创建类T,请注意T是X的公共内部子类。如果是,则如何定义规则。 I am using Digester 2.x, or introduce some better design 我正在使用Digester 2.x,或介绍一些更好的设计

First off, why XML? 首先,为什么要使用XML? JSON is the way to go. JSON是必经之路。 Check out google's GSON lib for serializing Java objects. 检出Google的GSON库以序列化Java对象。 Its a great library. 它是一个很棒的图书馆。 Otherwise, here's a Digester tutorial: http://www.javacodegeeks.com/2012/09/apache-digester-example-make-easy.html 否则,这里有一个Digester教程: http : //www.javacodegeeks.com/2012/09/apache-digester-example-make-easy.html

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

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