简体   繁体   English

如何将xml属性值映射到属性文件中的键?

[英]How do i map xml attribute values to keys in properties file?

This my test.xml file: 这是我的test.xml文件:

<?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=12345date=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.

相关问题 Micronaut:我如何 map HashMap 中的所有属性值? - Micronaut: How do I map all the properties values in HashMap? 如何在XML属性值中包含&,<,>等 - How do I include &, <, > etc in XML attribute values java.util.Properties:如何从spring config xml中的Properties检索值 - java.util.Properties: How do I retrieve values from Properties in spring config xml 我如何从石英调度程序的属性文件中获取值? - how do i get values from a properties file in quartz scheduler? 如何映射ModelAttribute的属性? - How do I map properties of a ModelAttribute? Java如何在特定键中获取所有映射值? - Java How do I get all map values within specific keys? 如何将带有键和值的树图放入升序列表中? - How do I put a tree map with keys and values sorted into an ascending list? 如何在Swift中以日期作为键和布尔值作为值来创建字典/地图? - How do I create a dictionary/map in Swift with dates as keys and booleans as values? 如何在Java中合并两个对象的属性? (用户定义的类的属性和Map的键值) - How to merge properties of two objects in Java? (properties of user defined class and keys values of Map) 如何将哈希图的键和值设置为xml文件的标记和值 - How to set keys and values of a hashmap as tags and values of a xml file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM