[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    [jira] [Commented] (CONFIGURATION-560) Receiving duplicate list entries for XPATH expression on XML
From:       "Oliver Heger (JIRA)" <jira () apache ! org>
Date:       2013-11-29 20:53:35
Message-ID: JIRA.12679732.1384783721445.48170.1385758415213 () arcas
[Download RAW message or body]


    [ https://issues.apache.org/jira/browse/CONFIGURATION-560?page=com.atlassian.jira. \
plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13835540#comment-13835540 \
] 

Oliver Heger commented on CONFIGURATION-560:
--------------------------------------------

Any updates here? Did this solve your problem? Can we close this ticket?

> Receiving duplicate list entries for XPATH expression on XML document via \
>                 org.apache.commons.configuration.HierarchicalConfiguration.configurationsAt
>                 
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>  
> Key: CONFIGURATION-560
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-560
> Project: Commons Configuration
> Issue Type: Bug
> Affects Versions: 1.10
> Reporter: Martin Schlegel
> 
> The XPATH expression used selects only one element, but getList and \
> configurationsAT retrieves the same element twice ... or I am simply not getting \
> the manual :-) Please see the simple example code attached below.
> Fedora Linux FC 17
> Java 1.7
> Apache Commons Components used:
> commons-collections-3.2.1.jar
> commons-configuration-1.10.jar
> commons-jxpath-1.3.jar
> commons-lang-2.6.jar
> commons-logging-1.1.3.jar
> XML document "sample.xml":
> ____________________________________________
> <?xml version="1.0" encoding="UTF-8"?>
> <config>
> 	<names>
> 		<firstname id="1"> Peter   </firstname>
> 		<firstname id="2"> Michael </firstname>
> 		<firstname id="3"> Alex    </firstname>
> 	</names>
> </config>
> ____________________________________________
> Java code:
> ____________________________________________
> import java.util.List;
> import org.apache.commons.configuration.ConfigurationException;
> import org.apache.commons.configuration.HierarchicalConfiguration;
> import org.apache.commons.configuration.XMLConfiguration;
> import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
> public class xmltest {
> 	public static void main(String[] args) {
> 		
> 		XMLConfiguration XMLconfig;
> 		try {
> 			XMLconfig = new XMLConfiguration("/tmp/sample.xml");
> 			XMLconfig.load();
> 			XMLconfig.setExpressionEngine(new XPathExpressionEngine());
> 			
> 			System.out.println("Retrieving firstname with id=2 via configurationsAt() ...");
> 			List<HierarchicalConfiguration> fields = \
> XMLconfig.configurationsAt("names/firstname[@id='2']");  for \
> (HierarchicalConfiguration sub : fields) {  System.out.println("=> \
> names/firstname[@id='2'] = " + sub.getString("."));  }
> 			System.out.println("\nRetrieving firstname with id=2 via getList() ...");
> 			List<Object> liObjects = XMLconfig.getList("names/firstname[@id='2']");
> 			for (Object obj : liObjects) {
> 				System.out.println("=> names/firstname[@id='2'] = " + (String) obj);
> 			}
> 			
> 			System.out.println("\nRetrieving firstname with id=2 via getString() ...");
> 			System.out.println("=> names/firstname[@id='2'] = " + \
> XMLconfig.getString("names/firstname[@id='2']"));  }
> 		catch (ConfigurationException e) {
> 			e.printStackTrace();
> 		}
> 	}
> }
> ____________________________________________
> Output:
> ____________________________________________
> Retrieving firstname with id=2 via configurationsAt() ...
> => names/firstname[@id='2'] = Michael
> => names/firstname[@id='2'] = Michael
> Retrieving firstname with id=2 via getList() ...
> => names/firstname[@id='2'] = Michael
> => names/firstname[@id='2'] = Michael
> Retrieving firstname with id=2 via getString() ...
> => names/firstname[@id='2'] = Michael
> ____________________________________________



--
This message was sent by Atlassian JIRA
(v6.1#6144)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic