简体   繁体   中英

Groovy XML Parser Dollar Sign in Attribute $

I am using XMLParser to parse an xml document that has the following structure:

<Tag>
    <SubTag att1="some.directory.structure.ClassName$InternalClass" att2="value2"/>
</Tag>

I am trying to store the value of att1 in a String with:

def att1Value = root.Tag[0].iterator().toList()[0]['@att1']

However, when I read att1Value, it's value is "some.directory.structure.ClassName". Is Groovy treating the $InternalClass as a variable? How do I capture the whole value of att1?

Thanks.

This code:

xml = '''<Tag>
    <SubTag att1="some.directory.structure.ClassName$InternalClass" att2="value2"/>
</Tag>'''

root = new XmlParser().parseText( xml )

att1value = root.SubTag[0].@att1

Gives me the result

"some.directory.structure.ClassName$InternalClass"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM