Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8354151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:28:11+00:00 2026-06-09T09:28:11+00:00

I am having difficulty adding a node deeper in an xml structure. I am

  • 0

I am having difficulty adding a node deeper in an xml structure. I am missing something between and node and nodeList. Any help would be greatly appreciated.

def xml='''<Root id="example" version="1" archived="false">
<Item name="one" value="test"/>
<Item name="two" value="test2"/>
<Item name="three" value="test3"/>
<AppSettings Name="foo" Id="foo1">
    <roles>foo</roles>
</AppSettings>
<AppSettings Name="bar" Id="bar1">
    <Item name="blue" value=""/>
    <Item name="green" value=""/>
    <Item name="yellow" value=""/>
    <Roles>
        <Role id="A"/>
        <Role id="B"/>
        <Role id="C"/>
    </Roles>
</AppSettings>
</Root>'''

root = new XmlParser().parseText(xml)
def appSettings = root.'AppSettings'.find{it.@Name == "bar"}.'Roles'
appSettings.appendNode('Role', [id: 'D'])


def writer = new StringWriter()
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.preserveWhitespace = true
printer.print(root)
String result = writer.toString()

println result

Error

groovy.lang.MissingMethodException: No signature of method: groovy.util.NodeList.appendNode() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap) values: [Role, [id:D]]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:28:12+00:00Added an answer on June 9, 2026 at 9:28 am

    This line here:

    def appSettings = root.'AppSettings'.find{it.@Name == "bar"}.'Roles'
    

    is returning you a NodeList (containing a single node), so you want to call appendNode on the contents of this list, not on the list itself.

    This can be done either by:

    appSettings*.appendNode('Role', [id: 'D'])
    

    Which will call appendNode on every element of the list, or by:

    appSettings[0]?.appendNode('Role', [id: 'D'])
    

    Which will call appendNode on the first element of the list (if there is a first element thanks to the null-safe operator ?).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a difficulty adding an item to my listbox. I want to
Im having difficulty trying to design a database structure for the following scenario: My
Okay, so I seem to be having a bit of difficulty in adding ShareKit
I'm having some difficulty creating nested objects between a one-to-many relationship. My models are
Hey Guys I'm having difficulty adding LIKE into my UNION, it seems to either
I'm having a difficulty adding form elements together. If you could check out my
I'm having difficulty adding to the end of an array. Not sure how to
I'm having a bit of difficulty adding some CSS to a link. I'm using
Having difficulty indexing an attachment type in elasticsearch via the Tire gem. Not able
I'm having difficulty iterating through records while scrolling window. My initial thought was to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.