How to get children of Node element

Hi,

How can I get to read children of “UserInfo” node. For example I want FirstName, LastName, Age and State (parameters and their values). I’ve tried using the XPathExpression but not seeing the results I want. Please assist.

inputFile has following xml text.

      <GetUserInfoResponse>
  **      <Return>
  **        <UserInfo>
  **        	<FirstName>David</FirstName>
  **		<LastName>Hunter</LastName>
  **		<Age>45</Age>
  **		<State>Main</State>        
  **        </UserInfo>
  **      </Return>
  **    </GetUserInfoResponse>"

public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException
{
File inputFile = new File(“C:\Automation\Test.txt”);

	Document doc = builder.parse(inputFile);
	doc.getDocumentElement().normalize();
	
	// Creating an Xpath to access the node
	XPathFactory xpathfactory = XPathFactory.newInstance();
	XPath xpath = xpathfactory.newXPath();
	
	XPathExpression ex = xpath.compile("//GetUserInfoResponse/Return/UserInfo");
	Object res = ex.evaluate(doc, XPathConstants.NODESET);
	NodeList nList = (NodeList) res;
	
	System.out.println("Length = " + nList.getLength());

	for (int j = 0; j < nList.getLength(); j++)
	{
		System.out.println("Node Name = " +nList.item(j).getChildNodes());
	}

}

What is ** ?

What is " at the very end of the text?

Do you really find these characters in the text? These characters look very unusual in a XML.

Then what do you see in the console? Any error message?

You seem to be trying to write a Java-class like thing in Katalon Studio. But Katalon Studio does not support it. Are you aware of it? You should code a Groovy script which is so-called Test Case. It is slightly different from a Java class with public static void main() method. Do you understand. it?

Thank you so much for the reply. When posting the question I realized the xml code was showing in the post, so when I added the ** it showed. The ** is not in my xml file.
As for the main function, I normally work in eclipse then copy cut paste the code to test case in katalon.
Thanks

public void main(String[] args) {} in Test Case will not be called by Groovy runtime in Katalon Studio.

What to do next? — Just strip it.

Let me suppose you have a Java class:

public class Sample {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    } 
} 

Then your Test Case should look like:

System.out.println("Hello, world!")

or

println "Hello, world!"

Do you want to use javax.xml.xpath.XPath and related classes in Katalon Studio 7.9.1?

Unfortunately you will encounter more problems. I know KS 7.9.1 has a problem around XML processing.

@ThanhTo
@duyluong

One more person is going to be trapped by stax-api-1.0.1.jar bundled in KS 7.9.x.

I suppose that, in KS 7.9.1, all who want to test Web Service with XML response will have hard time due to stax-api-1.0.1.jar.

You should announce to them that they should stay using KS 7.8.x or older, should not upgrade to KS 7.9.1.