commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lucas Reginato <>
Subject [jxpath] - Error trying to query boolean values
Date Tue, 03 Jul 2012 21:41:38 GMT

I’m facing a strange behavior using xPath to query boolean values.

Every time I tried to query boolean values with xPath, I get an exception
saying that no value was found.

The exception is:

org.apache.commons.jxpath.JXPathNotFoundException: No value for xpath:

Let me present the complete example that I'm using:

This is my schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="" xmlns:xsi="" xmlns="http://mySchema"
xmlns:jaxb="" xmlns:xjc="" targetNamespace="http://mySchema"
elementFormDefault="qualified" jaxb:extensionBindingPrefixes="xjc"
    <!--         Base type definitions    -->
    <xs:complexType name="MyEntity">
            <xs:element name="Id" type="xs:string" minOccurs="0"
            <xs:element name="Name" type="xs:string" minOccurs="0"
            <xs:element name="IsUsaResident" type="xs:boolean"
minOccurs="0" maxOccurs="1"/>
            <xs:element name="AnotherBooleanValue" type="xs:boolean"
minOccurs="0" maxOccurs="1"/>
    <!--        Root Element    -->
    <xs:element name="MyEntity" type="MyEntity"/>

In order to generate my java classes based on the schema, I'm using the xjc
ant tag.

My generated class looks like this:

package myschema;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "MyEntity", propOrder = {
public class MyEntity implements Serializable{
    @XmlElement(name = "Id")
    protected String id;
    @XmlElement(name = "Name")
    protected String name;
    @XmlElement(name = "IsUsaResident")
    protected Boolean isUsaResident;
    @XmlElement(name = "AnotherBooleanValue")
    protected Boolean anotherBooleanValue;
    public String getId() { return id; }
    public void setId(String value) { = value; }
    public String getName() { return name; }
    public void setName(String value) { = value; }
    public Boolean isIsUsaResident() { return isUsaResident; }
    public void setIsUsaResident(Boolean value) { this.isUsaResident =
value; }
    public Boolean isAnotherBooleanValue() { return anotherBooleanValue; }
    public void setAnotherBooleanValue(Boolean value) {
this.anotherBooleanValue = value; }

And I'm using the following code to query boolean values:
 MyEntity myEntity = new MyEntity();
Object result = "";
JXPathContext context = JXPathContext.newContext(myEntity);
try {
result = context.getValue("/IsUsaResident");
if (result == null) {
result = "";
} catch (JXPathException exc) {

Can someone help me with this?

-Lucas Reginato

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message