【问题标题】:How to output xml namespace with Grails REST webservices如何使用 Grails REST Web 服务输出 xml 命名空间
【发布时间】:2023-03-29 02:45:01
【问题描述】:

它是一个 Grails 应用程序,我们希望能够将 XML 命名空间添加到为 REST 客户端生成的 xml 中。大多数 xml 是使用深度转换器的“render foo as XML”输出的。

所以输出需要是这样的: <foo xmlns:myns='http://mycompany.com/myproduct/ver'> ... </foo>

【问题讨论】:

    标签: xml rest grails namespaces


    【解决方案1】:

    http://groovy.codehaus.org/Creating+XML+using+Groovy%27s+MarkupBuilder

    def xml = new MarkupBuilder(writer)
    xml.'rec:records'('xmlns:rec': 'http://groovy.codehaus.org') {
      car(name:'HSV Maloo', make:'Holden', year:2006) {
        country('Australia')
        record(type:'speed', ' Truck with speed of 271kph')
      }
    }
    
    result
    
    <rec:records xmlns:rec='http://groovy.codehaus.org'>
      <car name='HSV Maloo' make='Holden' year='2006'>
        <country>Australia</country>
        <record type='speed'> Truck with speed of 271kph</record>
      </car>
    </rec:records>
    

    【讨论】:

    • 感谢亚伦的回复。我们正在使用“render foo as XML”构造,那么在这种情况下我们如何使用 MarkupBuilder 呢?在我们的案例中,进行手动序列化过程的工作量太大。
    • grails 不支持通过标准转换器,请参阅 bug jira.codehaus.org/browse/GRAILS-5152
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 2011-06-09
    相关资源
    最近更新 更多