English 中文(简体)
根据属性价值使用Casteror
原标题:using Castor to parse xml based on attribute values

使用Castor将以下xml分送进POJOs,使用绘图文档,这相当简单:

<human name="bob"/>
<dog owner="alice"/>

它使用该元素的名称绘制该类别地图。 但是,如果要利用一个特性来绘制地图? e.g:

<animal type="human" name="bob"/>
<animal type="dog" owner="alice"/>

这一有争议的例子基于我必须消费的XML(当时我就是这样说的作者!) 。 任何关于如何用种姓测绘档案来处理这一问题的想法?

最佳回答

这样做有两个途径。 改动 Java类结构具有人体和狗扩展动物,然后撰写动物地图。

或只是利用XSLT改变数据。 可能这样作:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="animal">
  <xsl:text disable-output-escaping="yes"><![CDATA[<]]></xsl:text>
       <xsl:value-of select="@type" /><xsl:text disable-output-escaping="yes"> </xsl:text>name="<xsl:value-of select="@name" />"
  <xsl:text disable-output-escaping="yes"><![CDATA[/>]]></xsl:text>
</xsl:template>
</xsl:stylesheet>
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签