【问题标题】:How to add List items in dom4j defaultDocument object?如何在 dom4j defaultDocument 对象中添加列表项?
【发布时间】:2021-02-02 16:35:34
【问题描述】:

我正在尝试使用对象列表更新 DefaultDocument 对象。

DefaultDocument 对象如下所示。

<page>
   <createdDate>2021-02-01T15:44:55.548Z</createdDate>
   <lastModifiedDate>2021-02-02T13:54:52.371Z</lastModifiedDate>
   <summary>Sample Summary</summary>
   <title>Title</title>
</page>

我有如下所示的键和值列表。

List<String> list = myList // Contains following values

[
{
"city" : "london",
"image" : { "key" : "someKey", "description" : "some description" },
"title" : "UK"
}
]

我正在尝试生成如下的 defaultDocument。

<page>
   <createdDate>2021-02-01T15:44:55.548Z</createdDate>
   <lastModifiedDate>2021-02-02T13:54:52.371Z</lastModifiedDate>
   <summary>Sample Summary</summary>
   <title>Title</title>
   <items>
       <city>london</city>
       <image>
           <key>someKey</key>
           <description>some description</description>
       </image>
       <title>UK</title>
   </items>
</page>

任何建议都会有所帮助。谢谢!

【问题讨论】:

    标签: java json xml dom4j


    【解决方案1】:

    你可以试试这个 xml 和 underscore-java 库。

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <element array="true">
        <city>london</city>
        <image>
          <key>someKey</key>
          <description>some description</description>
        </image>
        <title>UK</title>
      </element>
    </root>
    

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      相关资源
      最近更新 更多