commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lucas Reginato <lucas.regin...@gmail.com>
Subject Re: [jxpath] - Error trying to query boolean values
Date Wed, 04 Jul 2012 01:58:41 GMT
I will try to make this change (from is method to get method) tomorrow and
will send the results.

But imagine the scenario: you have a product (which was already shipped to
customers) that has an API.
And your product also presents the possibility to query values from XML
using Xpath.
What do you suggest for this specific product that was already shipped and
now customer are using xpath to retrieve boolean values without success?

Yes, we can use XSLT to get the boolean value, but I think apache should
fix this.
I mean, apache commons xpath should be able to work with get/set/is methods
and not only get/set.

Do you think it's possible to file a new issue for this?

-Lucas

On Tue, Jul 3, 2012 at 10:33 PM, Matt Benson <gudnabrsam@gmail.com> wrote:

> Good call; yes, being an Object Boolean, the "is" idiom does not work.
>
> Matt
>
> On Tue, Jul 3, 2012 at 8:11 PM, Lucas Reginato <lucas.reginato@gmail.com>
> wrote:
> > Yes,
> >
> > The example is incorrect, it should be lower case, my mistake.
> > If you try to execute my example you will see this issue.
> >
> > Did you see the java code that was generated?
> > Maybe if the is methods where change to get method, will it work?
> >
> > -Lucas
> >
> > On Tue, Jul 3, 2012 at 6:55 PM, Matt Benson <gudnabrsam@gmail.com>
> wrote:
> >>
> >> Have you tried "/isUsaResident"?  Javabean property names typically
> >> begin with lower case.
> >>
> >> HTH,
> >> Matt
> >>
> >> On Tue, Jul 3, 2012 at 4:41 PM, Lucas Reginato <
> lucas.reginato@gmail.com>
> >> wrote:
> >> > 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
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >> --
> >> Lucas Rosa Cruz Reginato
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
> --
> Lucas Rosa Cruz Reginato
>
>  <user-help@commons.apache.org>
>

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