commons-user mailing list archives

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



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:
<myXpath>


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


This is my schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns="http://mySchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="
http://java.sun.com/xml/ns/jaxb/xjc" targetNamespace="http://mySchema"
elementFormDefault="qualified" jaxb:extensionBindingPrefixes="xjc"
jaxb:version="2.0">
    <xs:annotation>
        <xs:appinfo>
            <jaxb:globalBindings>
                <xjc:serializable/>
            </jaxb:globalBindings>
        </xs:appinfo>
    </xs:annotation>
    <!--         Base type definitions    -->
    <xs:complexType name="MyEntity">
        <xs:sequence>
            <xs:element name="Id" type="xs:string" minOccurs="0"
maxOccurs="1"/>
            <xs:element name="Name" type="xs:string" minOccurs="0"
maxOccurs="1"/>
            <xs:element name="IsUsaResident" type="xs:boolean"
minOccurs="0" maxOccurs="1"/>
            <xs:element name="AnotherBooleanValue" type="xs:boolean"
minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
    <!--        Root Element    -->
    <xs:element name="MyEntity" type="MyEntity"/>
</xs:schema>


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 java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MyEntity", propOrder = {
    "id",
    "name",
    "isUsaResident",
    "anotherBooleanValue"
})
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) { this.id = value; }
    public String getName() { return name; }
    public void setName(String value) { this.name = 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();
myEntity.setId("1");
myEntity.setName("MyName");
myEntity.setIsUsaResident(true);
myEntity.setAnotherBooleanValue(false);
Object result = "";
JXPathContext context = JXPathContext.newContext(myEntity);
try {
result = context.getValue("/IsUsaResident");
if (result == null) {
result = "";
}
} catch (JXPathException exc) {
exc.printStackTrace();
}
System.out.println(result.toString());

Can someone help me with this?

Thanks,
-Lucas Reginato

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