I have a xml file and csv file i have tried updating my xml with the csv values but it is not getting added and returns null value.
The xml file csv content are shown below respectively..
def xmldata='''<data>
<TYPE name="Semester1">
<SUBTYPE name="girl" age="21"/>
</TYPE>
<TYPE name="semester2">
<SUBTYPE name="boy" age="23"/>
</TYPE>
</data>'''
def csv='''name,name,mark
semester1,girl,50
semester2,boy,75'''
I want to check if TYPE.name
and the SUBTYPE.name
of csv matches with xml and update them.
def root2 = new XmlSlurper().parseText(xmldata)
root2.TYPE.SUBTYPE.find{it.@name=='girl')}.@mark=50 //this is adding the values
How to check TYPE.name
matches with SUBTYPE.name
and add mark as another attribute ?
假设要在semester1中添加。
root2.TYPE.find{it.@name=='Semester1').SUBTYPE.find{it.@name=='girl')}.@mark=50
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.