开发者

Groovy XML Parser Dollar Sign in Attribute $

开发者 https://www.devze.com 2023-02-17 21:45 出处:网络
I am using 开发者_如何学JAVAXMLParser to parse an xml document that has the following structure:

I am using 开发者_如何学JAVAXMLParser 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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号