Hello. I am developing a Groovy script to work through all the tags in an
incoming text representation of an xml file. I've read my xml from the
content of a NiFi flowfile, like so:

session.read(ff, {inputStream ->
          text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
          def xml = new XmlParser().parseText(text)

Later in my code I iterate through the xml to find all the values
associated with that tag. Ultimately I will build a unique sorted list,
tagValues.

This is the code section that I have working so far:

incomingTagsMap.each {
               tagValues.clear()
              * xml.'**'.each { itt ->*
                    log.warn('Found this tag: {}, with this value: {}',
itt.name(), itt.text())
                    // If itt.text() is not on tagValues list, add it...
                    if ( !tagValues.contains(itt.text()) ) {
tagValues.add(itt.text()) }
                    log.warn('Length of tagValues list : {}',
tagValues.size())
               }
               log.warn('Tag {} has values: {}', ["$it.key",
tagValues.toListString()] as Object[])
          }

$it.key comes from an outer iterative loop.

Where I am failing:
I was hoping someone could help me tune this because in cases like this....
     <property name="User Group
Provider">file-user-group-provider</property>
...I only get *property *as the tag. What I really want to identify as my
tag is *User Group Provider*  .

I've been unable to find any examples. Can anyone show me how to accomplish
this?

Thanks very much in advance.
Cheers,
Jim

Reply via email to