Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Cannot convert XPath value to Java object: required class is org.w3c.dom.NodeList;

Options
Michelle
Michelle Posts: 14

Trying to run this XPath

for $index in (1 to count(/root ) )
return
( if (exists ( /root/items[$index]/item[]/sport[1] ) )
then /root/items[$index]/item[
]/sport[1]/text()

else
( if (exists ( /root/count[$index] ) )
then concat('Record Count = ' ,//root/count[$index]/text())
else
"N/A "))

or this one
for $index in (1 to count(/root ) )
return
( if (exists ( /root/items[$index]/item[]/sport[1] ) )
then /root/items[$index]/item[
]/sport[1]/text()
else
"N/A ")

I am trying to get get the NA or record count when the element is missing. This has worked in the past but for some reason is no longer working.

I have even checked to extract empty/missing values in the options section of the JSON data bank. But it is erroring out and the empty/missing values are not displaying in my data sources. So my data is off because the values go to the next available record

This is the error message that I am receiving

Cannot convert XPath value to Java object: required class is
org.w3c.dom.NodeList; supplied value has type xs:string

Answers

  • jakubiak
    jakubiak Posts: 801 admin
    Options

    What version of SOAtest are you using? Were you using a different version when it was working previously?

  • Michelle
    Michelle Posts: 14
    Options

    Good Morning,

    We are on Version: 9.10.7.20190506
    Build id: 2019-05-06-2044. I do not remember if it was a different version but I guess that could be possible.

    Is there a way to get it to work on this version?

    Thanks

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    edited May 2022
    Options

    Cannot convert XPath value to Java object: required class is
    org.w3c.dom.NodeList; supplied value has type xs:string

    Evaluating XPath expressions that return non Node/NodeList values like xs:string was implemented for the SOAtest 9.10.8 release.

    We are on Version: 9.10.7.20190506

    You need to be using at least SOAtest 9.10.8.

    In previous releases you would have to use an XPath expression that returns a node instead a string. So, you can change 'else "N/A"' to something like 'else parse-xml("<foo>N/A</foo>")/foo/text()'.

  • Michelle
    Michelle Posts: 14
    Options

    Thank you so i tried that

    for $index in (1 to count(/root/items[] ) )
    return
    ( if (exists ( /root/items[$index]/item[
    ]/sport[1] ) )
    then /root/items[$index]/item[*]/sport[1]/text()
    else parse-xml("NO SPORT")/foo/text() )

    So it will give me NO Sport for the first record and then nothing for the 2nd & 3rd records
    DisplayName Type Sport League
    The Open competitiongroup NO SPORT NO LEAGUE
    MLB The Show competitiongroup
    The Masters competitiongroup

    Then the below data will populate the empty rows and present incorrect data.

    DisplayName Type Sport League
    The Open competitiongroup NO SPORT NO LEAGUE
    MLB The Show competitiongroup soccer concacaf.nations.league
    The Masters competitiongroup football college-football

    This is what I would like to see.
    DisplayName Type Sport League
    The Open competitiongroup NO SPORT NO LEAGUE
    MLB The Show competitiongroup NO SPORT NO LEAGUE
    The Masters competitiongroup NO SPORT NO LEAGUE
    Bahamas @ event soccer concacaf.nations.league
    Georgia @ event football college-football
    N/A N/A N/A N/A

    Would like to see the data aligned properly. Not every record has all of the fields. That is where I am having issues.

    Thanks