【发布时间】:2011-04-10 15:05:22
【问题描述】:
我想要以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<structure:structuralDataRoot xmlns:register="http://www.test.ch/register/1" xmlns:structure="http://test.ch/structure/1" >
<structure:tester>ZH</structure:tester>
<structure:surveyYear>2001</structure:surveyYear>
<structure:surfaceData>
<structure:houseSurfaceData>
<structure:creationDate>2001-01-01</structure:creationDate>
<structure:localFarmId>
<register:houseIdCategory>token</register:houseIdCategory>
<register:houseId>token</register:houseId>
</structure:localFarmId>
</structure:houseSurfaceData>
</structure>
我可以像这样将命名空间添加到 xml:
xml.records('xmlns:structure' :"http://test.ch/structure/1" ...
但是如何为 xml 元素添加名称空间前缀? 我找到的唯一解决方案是:
tester('xmlns:structure' :"http://test.ch/structure/1", 'ZH')
但这给了我以下输出:
<tester xmlns:structure='http://test.ch/structure/1'>ZH</tester>
它的语法正确,但是当你有很多节点时不好看。
【问题讨论】:
标签: groovy namespaces markupbuilder