【问题标题】:Need Help in creating xml with list of nodes with different node name需要帮助创建具有不同节点名称的节点列表的 xml
【发布时间】:2013-06-09 07:28:35
【问题描述】:

我正在使用 xstream,想生成这样的 xml。

<relatedImages jcr:primaryType="nt:unstructured">
  <img0
    jcr:primaryType="nt:unstructured"
    assetPath="741414711.jpg"
    excludedTypes="[]"/>
  <img1
    jcr:primaryType="nt:unstructured"
    assetPath="741414712.jpg"
    excludedTypes="[]"/>
</relatedImages>

我知道 xstream 允许添加要转换为 xml 节点列表的对象列表,但在我的情况下,节点列表相同但节点名称不同。如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: java xml xstream


    【解决方案1】:
    /**
     * 
     * @param contentxml
     * @param xmlAttributeName
     * @param xmlAttributeValue
     * @return xml with inserted node value
     */
    private static String insertXmlAttributeValue(String xml, String xmlAttributeName, String xmlAttributeValue){
        if(StringUtils.isNotEmpty(xmlAttributeValue)){
            String xmlAttributeKey = xmlAttributeName + "=\"\"";
            xmlAttributeValue = xmlAttributeName + "=\""+ xmlAttributeValue+"\"" ;
            xml = xml.replace(xmlAttributeKey, xmlAttributeValue);
        }
        return xml;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多