Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.1.7
-
None
-
Win 8/64 java 1.7_40
Description
When trying to update (or remove) the xlink:title attribute in the following, one has to use the full namespaced tag name.
import groovy.xml.* def xmlSource = '''<bob:root xmlns:bob="stuff" xmlns:gmi="http://www.isotc211.org/2005/gmi" xmlns:xlink="http://www.w3.org/1999/xlink"> <gmi:instrument xlink:title="$INSTRUMENT"/> </bob:root>''' def bobRoot = new XmlSlurper(false, true).parseText(xmlSource).declareNamespace(bob: 'stuff', ns2: 'http://www.example.org/NS2', gmi: "http://www.isotc211.org/2005/gmi") def instrument = bobRoot.'gmi:instrument' // NB: does NOT work: instrument[0].attributes().remove('xlink:title') // does work: instrument[0].attributes().remove('{http://www.w3.org/1999/xlink}title') // NB: leads to duplicate attribute: instrument.'@xlink:title' = 'XXX' instrument.'@{http://www.w3.org/1999/xlink}title' = 'XXX' println instrument.'@xlink:title' println new StreamingMarkupBuilder().bind { mkp.yield instrument }.toString() 'OK'
I SHOULD be able to simply do:
instrument.'@xlink:title' = 'XXX'
Note that I can do:
println instrument.'@xlink:title'
So there is an inconsistency/incompleteness/confusion here.
I'm also wondering why I needed to use 'instrument[0]' to get at the attributes. Also seems 'odd' to me.