Java XPath returns single result instead of NodeSet

I am trying to create an XPath expression in Java (8, default XPath implementation). I am doing the following:

Object res = xpath.evaluate("(//*[local-name()='PartyId'])", requestDom, XPathConstants.NODESET);

I have multiple PartyId nodes in the document at the same level, because it's parent is repeating. I got my result, but only a single node. (the first).

Side info: if I write [$k] at the end of the expression, like [1], or [2], I got my elements, but I need all of them. :(

However, if I am testing the very same XPath for example at I get multiple results which is the expected result. Any ideas?

p.s. I tried to put Saxon on the classpath but it completely breaks my application (Spring-Boot WS).

Thanks a lot!

UPDATE I failed to correctly check the result and it was absolutely correct.

-------------Problems Reply------------

My guess is that you make a mistake while processing the result NodeList. Try the following approach:

NodeList results = (NodeList) xpath.evaluate(..);
for (int i = 0; i < nodelist.getLength(); i++) {
Node node = (Node) nodelist.item(i);

Category:java Views:2 Time:2019-01-05
Tags: xml java dom xpath

Related post

  • if? Sumproduct? Index? Vlookup just returns one result instead of the multiple results that I need 2012-02-16

    Vlookup just returns one result instead of the multiple results that I need. 1st Spreadsheet Product Model Serial # AA 98 73/2 AN 99 136/3 AN 100 136/4 AN 101 136/5 There are several lines that repeat with like an or CP or DK for instance. I have pro

  • java xpath return unexpected values 2012-03-13

    I'm builind an application which shows a map with the google api. Using the user input address, I query the API for directions to a destination. The API returns me a XML response which I parse to build my directions objects and show informations to t

  • Greasemonkey: XPath returns no results for .xhtml page 2009-01-17

    When running on an xhtml page, xpath doesn't seem to return any results. var result = document.evaluate( "//a/img", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); For example returns an empty result set. What's the problem here,

  • returning single result using LINQ 2011-01-22

    I have a query row.GetChildRows("EventCategoryRelation") .Where(categoryRow => categoryRow["event_id"].ToString() == eventObject.EventId.ToString()) .Select(x => Int32.Parse(x["category_id"].ToString())) This query returns an IEnumerable. I am

  • How to run Windows commands in JAVA and return the result text as a string 2012-01-22

    Possible Duplicate: Get output from a process Executing DOS commands from Java I am trying to run a cmd command from within a JAVA console program e.g.: ver and then return the output of the command into a string in JAVA e.g. output: string result =

  • Java integers Return Strange Result While Compare Two Integers? 2012-02-24

    Integer i1= new Integer(9); Integer i2= new Integer(9); if(i1==i2){ System.out.println("true"); }else{ System.out.println("false"); } int i3=9; int i4=9; if(i3==i4){ System.out.println("true"); }else{ System.out.println("false"); } if(i3==i2){ System

  • XPATH returning no results 2010-10-16

    I have an loaded some XML in an XMLDocument object. I am iterating through the document by using an For Each node As XmlNode In doc.GetElementsByTagName("Item", [NAMESPACE]) 'Do Stuff Next I would like to use xpath within this loop to pull out all no

  • Run bash scripts from JAVA and return the results 2012-02-02

    I am attempting to get output of a shell / bash script, that is run from a JAVA program, although I am not having much luck, the code is as follows: GetStats(winhostname); public static String winhostname "cmd /c hostname"; public static void GetStat

  • java getInputArguments() returns awkward results if system property value contains spaces 2012-02-03

    Consider a main method: public static void main(String[] args) throws Exception { System.out.println("property='" + System.getProperty("property") + "'"); List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments(); System

  • Query on entity with oneToMany relationship return 3 results instead of 1 2012-03-13

    I have an DecisionEntity that has bidirectional OneToMany relationship to ExplanationEntity. The SpecificDecisionEntity extends DecisionEntity and adds unidirectional manyToOne relationship to the CharacteristicEntity by field other than id. I create

  • mysql return single result from single table with complex condition 2012-04-30

    I have this table : table(fied1 int,field2 int,field3 varchar(40)); I would like to obtion without a stored procedure something like: declare int nr default 0; select coalesce(max(field1),0) into nr from table where field2=? and field3=?; if(nr = 0)

  • Java SimpleDateFormat returns unexpected result 2011-08-01

    I'm trying to use SimpleDateFormat of Java to parse a String to date with the following code. public class DateTester { public static void main(String[] args) throws ParseException { String dateString = "2011-02-28"; SimpleDateFormat dateFormat = new

  • What performs better: multiple single-result sql server stored procedures or single multple-result stored procedure 2010-08-09

    Background: I use stored procedures exclusively for an ASP.NET application. I am using a DataReader to load a dataset object. --------------Solutions------------- Single procedures returning single results (for code maintenability, simplicity and reu

  • XPath returning string or boolean in VBA? 2010-11-07

    What is the easiest way for a Word macro to execute XPath expressions such as: "string(/alpha/beta)" "not(string(/alpha/beta)='true')" which should return string and boolean respectively? (as opposed to an xml node or node list) I want to avoid DLLs

  • PHP while returns same result repeatedly 2013-04-29

    When running a while script on my local xampp it just returns the same result over and over again, here's the PHP I'm using: <?php $id = $_GET['id']; $getmembers = mysql_query("SELECT * FROM group_memberships WHERE groupid = $id LIMIT 10"); $getid

  • java - return two results in one function call? 2012-02-17

    This question already has an answer here: How to return multiple objects from a Java method? 19 answers I'm trying to do something like this: public void <String,int> getItem { return <"Jen",23>; } I know I can use a custom class, but how

  • Library for .NET that returns SPARQL results in some structured List instead of standard XML format? 2010-04-08

    Is there any Library for .NET that returns SPARQL results in some structured List instead of standard XML format? I am using SemWeb. I could not find any such method. --------------Solutions------------- SemWeb does appear to provide the building blo

  • Django custom SQL returning single row of results when query returns 2? 2010-04-17

    I have a custom SQL call that is returning different results to the template than I get when I run the same query against the database directly, 1 row vs 2 Query - copied from Django Debug Toolbar: SELECT ((Sum(new_recruit_interviews) / Sum(opportuni

  • Java: ArrayList returns Object instead of desired type 2010-07-16

    I'm having a problem that I have encountered before, but I still don't know why it happens. This is the code: package Program; import java.util.ArrayList; import java.util.Iterator; /** * This class will hold the full collection of the user. * * @aut

  • Java: Connect to Database and return query result 2011-02-23

    I am trying to connect to a SQL Server database in Java, execute a query, and return the result to the calling script. class DB { public DB() {} public Connection dbConnect(String db_connect_string) { try { Class.forName( "

  • How can I return multiple results from a single LinQ to SQL expression in one round-trip? 2011-08-30

    I'm rewriting an ancient piece of code that I've inherited and I'm looking at a query that performs a massive join on large tables, and then does a series of grouping actions on the resulting table to "distill out" data: INSERT INTO #teh_temp_table S

  • Resolving "The method must return a result of type int" in Java 2011-11-03

    I'm very new to Java. Eclipse is giving me the error The method must return a result of type int for the following code: public class firstprog { public static int largest(int a, int b, int c) { if (a > b) { if (a > c) { return a; } else if (b

  • A simple Java code returns some unexpected result 2011-11-14

    The following simplest Java code returns some unexpected output. Let's look at it. package interchange; final public class Main { public static void main(String[] args) { int x = 15; int y = 20; x^=y^=x^=y; System.out.println("x = " + x + "; y = " +

  • Ajax submit event displays the json result returned from controller instead of alert 2014-05-17

    i have a view which contains javascript code to submit data to the controller The Data is processed successfully at the controller however the page display the json result returned from controller instead of alert. any idea ? here is my code <code

Copyright (C), All Rights Reserved.

processed in 0.157 (s). 11 q(s)