我需要为xml标签添加名称空间,这是使用StreamMarkupBuilder.bind
开发的,下面给出了更多详细信息。
我的XML关注,
String xml =`<CarXml>
<Cars>
<Car>
<CarDetails>
<Model>Chevrolet Colorado</Model>
<Transmission code='A'>Automatic</Transmission>
<AirCondType code='R'>Yes</AirCondType>
<Passengers>4</Passengers>
<Doors>2</Doors>
<Luggage>
<Large>12</Large>
</Luggage>
</CarDetails>
</Car>
</Cars>
</CarXml>`
def parsed = new XmlSlurper(false, false).parseText( xml )
String request = new StreamingMarkupBuilder().bind {
CarRequest(xmlns="http://maven.apache.org/POM/4.0.0")
{
CarRateRulesRequestDetails()
{
mkp.yield parsed.Cars.Car.children()
}
}
}
这样做后我得到了这个
<CarRequest xmlns="http://maven.apache.org/POM/4.0.0">
<CarRateRulesRequestDetails>
<CarDetails>
<Model>Chevrolet Colorado</Model>
<Transmission code='A'>Automatic</Transmission>
<AirCondType code='R'>Yes</AirCondType>
<Passengers>4</Passengers>
<Doors>2</Doors>
<Luggage>
<Large>12</Large>
</Luggage>
</CarDetails>
</CarRateRulesRequestDetails>
</CarRequest>
但我想要的是
<CarRequest xmlns="http://maven.apache.org/POM/4.0.0">
<CarRateRulesRequestDetails>
<CarDetails xmlns="http://maven.apache.org/POM/4.0.0">
<Model xmlns="http://maven.apache.org/POM/4.0.0">Chevrolet Colorado</Model>
<Transmission code='A'>Automatic</Transmission>
<AirCondType code='R'>Yes</AirCondType>
<Passengers>4</Passengers>
<Doors>2</Doors>
<Luggage>
<Large>12</Large>
</Luggage>
</CarDetails>
</CarRateRulesRequestDetails>
</CarRequest>
如何在这种情况下添加命名空间..? 任何帮助都很受欢迎..