首页 > 解决方案 > 是否可以将动态值从 .properties 文件传递​​给 xml 文件的标签

问题描述

我有大约 100 个带有重复静态值的纯 xml 文件。我想通过从 .properties 文件中获取值将它们更改为动态值,以便我可以在一个地方更改该值。可能吗??

我拥有的当前 xml 示例:

<?xml version="1.0"?>
<bookstore>
  <book category="children">
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>  
</bookstore>

**desired change:**

**prop.properties.com**
bookName=Harry Potter
authorName=J K. Rowling
yearValue=2005
priceValue=29.99

<?xml version="1.0"?>
<bookstore>`enter code here`

//load properies file

  <book category="children">
    <title>${bookName}</title>
    <author>${authorName}</author>
    <year>${yearValue}</year>
    <price>${priceValue}</price>
  </book>  
</bookstore>

标签: javaxml

解决方案


推荐阅读