I have a query that bring back a cell in my table the has all xml in it. I have it so I can spit out what is in the cell without any delimiters. Now i need to actually take each individual element and link them with my object. Is there any easy way to do this?

    def sql
    def dataSource
    static transactional = true


  def pullLogs(String username, String id) { 
    if(username != null && id != null) {

    sql = new Sql(dataSource)
    println "Data source is: " + dataSource.toString()
    def schema = dataSource.properties.defaultSchema

    sql.query('select USERID, AUDIT_DETAILS from DEV.AUDIT_LOG T WHERE XMLEXISTS(\'\$s/*/user[id=\"' + id + '\" or username=\"'+username+'\"]\' passing T.AUDIT_DETAILS as \"s\") ORDER BY AUDIT_EVENT', []) { ResultSet rs ->
        while (rs.next()) { 
            def auditDetails = new XmlSlurper().parseText(rs.getString('AUDIT_EVENT_DETAILS'))
            println auditDetails.toString
        }
    }
    sql.close()
  }
}

now this will give me that cell with those audit details in it. Bad thing is that is just puts all the information from the field in on giant string without the element tags. How would I go through and assign the values to a object. I have been trying to work with this example http://gallemore.blogspot.com/2008/04/groovy-xmlslurper.html with no luck since that works with a file.

I have to be missing something. I tried running another parseText(auditDetails) but haven't had any luck on that.

Any suggestions?

EDIT:

The xml int that field looks like

<user><username>scottsmith</username><timestamp>tues 5th 2009</timestamp></user>

^ simular to how it is except mine is ALOT longer. It comes out as "scottsmithtue 5th 2009" so on and so forth. I need to actually take those tags and link them to my object instead of just printing them in one conjoined string.

有帮助吗?

解决方案

Just do

auditDetails.username

Or

auditDetails.timestamp

To access the properties you require

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top