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

  • SEARCH
  • Home
  • 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 4622046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:47:18+00:00 2026-05-22T02:47:18+00:00

I have this xml, i took it in xml a GPathResult object how can

  • 0

I have this xml, i took it in xml a GPathResult object how can I get Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition based on checking with the field value as OS Name using groovy xml slurping

<client productname="abp">
<machine>
  <env>
   <variable name='ALLUSERSPROFILE' value='C:\Documents and Settings\All Users' />
   <variable name='APPDATA' value='C:\Documents and Settings\Administrator\Application Data' />
   <variable name='OS' value='Windows_NT' />
   <variable name='COMPUTERNAME' value='AbhishekPC' />
 </env>
 <osinfo>
    <osinfo field='OS Name' information='Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition' />
    <osinfo field='OS Version' information='5.2.3790 Service Pack 2 Build 3790' />
    <osinfo field='OS Manufacturer' information='Microsoft Corporation' />
    <osinfo field='OS Configuration' information='Standalone Server' />
    <osinfo field='OS Build Type' information='Multiprocessor Free' />
 </osinfo>
</machine>
</client>

Here is the parsing code

def file = new File(filepath)
def gpathResult = new XmlSlurper().parse(file)

summary.productname=gpathResult.@product.text()
            log.info gpathResult.system.osinfo.osinfo.@field.text()


            System.out.println("HI 1"+gpathResult.machine.environment.variable.@name.text());
            System.out.println("HI 2"+gpathResult.machine.osinfo.osinfo.@field.text());

            if(gpathResult.machine.environment.variable.@name.text().equals("OS"))
            {   
                summary.osname=gpathResult.machine.environment.variable.@value.text()

            }
            if(gpathResult.machine.environment.variable.@name.text().equals("COMPUTERNAME"))
            {   
                summary.hostname=gpathResult.machine.environment.variable.@value.text()
            }

Here HI 1 prints all the environments name attribut values but HI 2 only prints HI 2

here is the snapshot
enter image description here

here is what solved after i traversed

      def    vals1=gpathResult.machine.env.variable.findAll{it.@name=='COMPUTERNAME'}.@value.text()
            println vals1
            csmSummary.hostname=vals1
            def vals2=gpathResult.machine.env.variable.findAll{it.@name=='OS'}.@value.text()
            println vals2
            csmSummary.osname=vals2
  • 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-05-22T02:47:19+00:00Added an answer on May 22, 2026 at 2:47 am

    Strange… if I do this (with Groovy 1.8)

    def gpathResult = new XmlSlurper().parseText( $/<client productname="abp">
    <machine>
      <env>
       <variable name='ALLUSERSPROFILE' value='C:\Documents and Settings\All Users' />
       <variable name='APPDATA' value='C:\Documents and Settings\Administrator\Application Data' />
       <variable name='OS' value='Windows_NT' />
       <variable name='COMPUTERNAME' value='AbhishekPC' />
     </env>
     <osinfo>
        <osinfo field='OS Name' information='Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition' />
        <osinfo field='OS Version' information='5.2.3790 Service Pack 2 Build 3790' />
        <osinfo field='OS Manufacturer' information='Microsoft Corporation' />
        <osinfo field='OS Configuration' information='Standalone Server' />
        <osinfo field='OS Build Type' information='Multiprocessor Free' />
     </osinfo>
    </machine>
    </client>/$ )
    
    println "HI 1 ${gpathResult.machine.env.variable.@name*.text()}"
    println "HI 2 ${gpathResult.machine.osinfo.osinfo.@field*.text()}"
    

    it prints out:

    HI 1 [ALLUSERSPROFILE, APPDATA, OS, COMPUTERNAME]
    HI 2 [OS Name, OS Version, OS Manufacturer, OS Configuration, OS Build Type]
    

    Can you try that code (assuming you are using 1.8, the latest version of Groovy — if not, you will need to use """ instead of $/ for the string delimiters, and escape the \ chars)

    [edit] It’s probably just because you are using gpathResult.machine.environment.variable instead of gpathResult.machine.env.variable

    to traverse the env nodes, you’d do something like:

    gpathResult.machine.env.variable.each { node ->
      println "${node.@name.text()} contains ${node.@value.text()}"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please help me, I have this xml snippet <?xml version=1.0 encoding=utf-8 ?>
I have this XML in a column in my table: <keywords> <keyword name=First Name
Lets assume we have this xml: <?xml version=1.0 encoding=UTF-8?> <tns:RegistryResponse status=urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure xmlns:tns=urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0 xmlns:rim=urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0> <tns:RegistryErrorList
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
I have to replace the content of this xml string through java <My:tag>value_1 22&#xA;value_2
I have seen this in a lot of XML comments for classes in the
I have only this in my mxml source code: <?xml version=1.0 encoding=utf-8?> <mx:Canvas xmlns:mx=http://www.adobe.com/2006/mxml
I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>

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.