JAVA: Build XML document using XPath expressions

前端 未结 3 1996
北荒
北荒 2020-12-10 15:49

I know this isn\'t really what XPath is for but if I have a HashMap of XPath expressions to values how would I go about building an XML document. I\'ve found dom-4j\'s Docu

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 16:13

    The best I was able to come up with is to use a JAXB implementation, which will marshall/unmarshal objects to xml and then I used Dozer (http://dozer.sourceforge.net/documentation/mapbackedproperty.html) to map the xpaths which were keys in a map to the JAXB object method setters.

    
    java.util.Map
    org.example.Foo
    
      this
      Foo.entity.att
      java.lang.String
    
    

    It's more of a two step solution, but really worked for me.

提交回复
热议问题