def studentRecords = '''
<students>
<student name='sname' id='sid' college='collegename' />
</students>
'''
def records = new XmlParser().parseText(studentRecords)
def requiredMap = records.student[0].attributes()
log.info "entrySet() shows name value pairs ==> "+requiredMap.entrySet()
// An EntrySet is just a thin wrapper providing a view of objects that already exist inside the HashMap
log.info "keySet() shows only keys ==> "+requiredMap.keySet()
log.info "containsKey, check if id tag is present ==> "+requiredMap.containsKey("id")
log.info "conatinsValue, check if id tag VALUE is present ==> "+requiredMap.containsValue("sid")
log.info "get value of the key id ==> "+requiredMap.get("id")
log.info "check if map is empty ==> "+requiredMap.isEmpty()
log.info "add value to map ==> "+requiredMap.put("sagar" , "singh")
log.info "entrySet() values are ==> "+requiredMap.entrySet()
//log.info "remove from map ==> "+requiredMap.remove("sagar")
//log.info "entrySet() values are ==> "+requiredMap.entrySet()
OUTPUT
Sun Nov 23 19:11:59 IST 2014:INFO:entrySet() shows name value pairs ==> [name=sname, id=sid, college=collegename]
Sun Nov 23 19:11:59 IST 2014:INFO:keySet() shows only keys ==> [name, id, college]
Sun Nov 23 19:11:59 IST 2014:INFO:containsKey, check if id tag is present ==> true
Sun Nov 23 19:11:59 IST 2014:INFO:conatinsValue, check if id tag VALUE is present ==> true
Sun Nov 23 19:11:59 IST 2014:INFO:get value of the key id ==> sid
Sun Nov 23 19:11:59 IST 2014:INFO:check if map is empty ==> false
Sun Nov 23 19:11:59 IST 2014:INFO:add value to map ==> null
Sun Nov 23 19:11:59 IST 2014:INFO:entrySet() values are ==> [name=sname, id=sid, college=collegename, sagar=singh]
Sun Nov 23 19:11:59 IST 2014:INFO:remove from map ==> singh
Sun Nov 23 19:11:59 IST 2014:INFO:entrySet() values are ==> [name=sname, id=sid, college=collegename]
<students>
<student name='sname' id='sid' college='collegename' />
</students>
'''
def records = new XmlParser().parseText(studentRecords)
def requiredMap = records.student[0].attributes()
log.info "entrySet() shows name value pairs ==> "+requiredMap.entrySet()
// An EntrySet is just a thin wrapper providing a view of objects that already exist inside the HashMap
log.info "keySet() shows only keys ==> "+requiredMap.keySet()
log.info "containsKey, check if id tag is present ==> "+requiredMap.containsKey("id")
log.info "conatinsValue, check if id tag VALUE is present ==> "+requiredMap.containsValue("sid")
log.info "get value of the key id ==> "+requiredMap.get("id")
log.info "check if map is empty ==> "+requiredMap.isEmpty()
log.info "add value to map ==> "+requiredMap.put("sagar" , "singh")
log.info "entrySet() values are ==> "+requiredMap.entrySet()
//log.info "remove from map ==> "+requiredMap.remove("sagar")
//log.info "entrySet() values are ==> "+requiredMap.entrySet()
OUTPUT
Sun Nov 23 19:11:59 IST 2014:INFO:entrySet() shows name value pairs ==> [name=sname, id=sid, college=collegename]
Sun Nov 23 19:11:59 IST 2014:INFO:keySet() shows only keys ==> [name, id, college]
Sun Nov 23 19:11:59 IST 2014:INFO:containsKey, check if id tag is present ==> true
Sun Nov 23 19:11:59 IST 2014:INFO:conatinsValue, check if id tag VALUE is present ==> true
Sun Nov 23 19:11:59 IST 2014:INFO:get value of the key id ==> sid
Sun Nov 23 19:11:59 IST 2014:INFO:check if map is empty ==> false
Sun Nov 23 19:11:59 IST 2014:INFO:add value to map ==> null
Sun Nov 23 19:11:59 IST 2014:INFO:entrySet() values are ==> [name=sname, id=sid, college=collegename, sagar=singh]
Sun Nov 23 19:11:59 IST 2014:INFO:remove from map ==> singh
Sun Nov 23 19:11:59 IST 2014:INFO:entrySet() values are ==> [name=sname, id=sid, college=collegename]
No comments:
Post a Comment