[英]How do i map xml attribute values to keys in properties file?
<?xml version="1.0" encoding="UTF-8"?>
<Class name="AirwayBill">
<Attribute name="billNo" primary="true" />
<Attribute name="date" primary="true" />
<Attribute name="person" class_name="Person" />
</Class>
<Class name="Person">
<Attribute name="perId" primary="true" />
<Attribute name="fname" primary="false" />
<Attribute name="lname" primary="false" />
There is also a .properties
file containing key value pairs like billNO=12345
, date=16/07/2014
. 还有一个.properties
文件,其中包含键值对,例如billNO=12345
, date=16/07/2014
billNO=12345
。
I want to map attributes between each corresponding key from properties and xml files. 我想在属性和xml文件的每个对应键之间映射属性。
How do i do that? 我怎么做? I am able to read both, attribute values and keys, and I am storing each one in a List. 我既可以读取属性值也可以读取键,并且可以将每个值存储在一个列表中。
if you want something like this: 如果您想要这样的话:
<someBean>
<properties>
<myProperty1>My Value 1</myProperty1>
<myProperty2>My Value 1</myProperty2>
</properties>
</someBean>
for a map: 对于地图:
My Property 1 My Value 1
My Property 2 My Value 2
code: 码:
@XmlAnyElement
public List<JAXBElement<String>> getXmlProperties() {
List<JAXBElement<String>> elements = new ArrayList<JAXBElement<String>>();
for (Map.Entry<String, String> property: properties.entrySet()) {
elements.add(new JAXBElement<String>(new QName(property.getKey()),
String.class, property.getValue()));
}
return elements;
}
This is the link which might be useful for you: Use JAXB XMLAnyElement type of style to return dynamic element names 这是对您可能有用的链接: 使用样式的JAXB XMLAnyElement返回动态元素名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.