Hi i'm new to groovy and I have a misunderstanding of how groovy parse xml
<schema-definition name="Standard" >
<field-type name="Standard:Integer" descr="A whole number." base-type="long"/>
<field-type name="Standard:Boolean" descr="A boolean value." base-type="boolean"/>
<field-type name="Standard:String" descr="A string" base-type="string"/>
</schema-definition>
When i try
document = groovy.xml.DOMBuilder.parse(new FileReader('D:/test.xml'))
rootElement = document.documentElement
use(groovy.xml.dom.DOMCategory)
{
field-types开发者_StackOverflow社区=rootElement.field-type
println field-types
}
I doesn't even compile: (field - types) is a binary expression, but it should be a variable expression at line: 13 column: 20
It doesn't compile because the "-" in field-types is an operator and therefore cannot be part of a name. Also, if you access the tag field-type you must use quotes, like this:
def fieldTypes = rootElement."field-type"
精彩评论