Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2154

properties of Node obscure xml elements with GPath after using XmlParser

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-beta-2
    • 1.5
    • XML Processing
    • None
    • Mac OS X, java 1.4-1.5

    Description

      def xml="""
      <doc>
      <name>My Doc Name</name>
      <description>this is my doc</description>
      </doc>
      """

      def p = new XmlParser()
      def doc = p.parseText(xml)

      def desc = doc.description[0].text()
      def name = doc.name[0].text() //exception

      groovy.lang.MissingMethodException: No signature of method: java.lang.String.text() is applicable for argument types: () values: {}

      Obviously the groovy.util.Node class' 'name' property is obscuring the element.

      I had to resort to this to get the value for the name element:

      def names = doc.directChildren.grep

      { node-> node.name=="name" }

      def name=nms[0].text()

      It seems like this conflict would happen for any elements with the same name as properties of the Node class.

      Attachments

        Activity

          People

            paulk Paul King
            gschueler Greg Schueler
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: