users@jaxb.java.net

RE: JAXB and JXPath

From: George Datuashvili <George.Datuashvili_at_Siebel.com>
Date: Thu, 6 May 2004 12:48:23 -0600

You could also use XPath for user defined filters over your data. For
instance search expression in find dialog, or in rules engine.

The problem is not the limited subset that JXPath understands, the
bigger problem is that JXPath is driven by reflection model. There are
two steps where model transformation looses information required for
Xpath interpreter: XML->XSD and XSD->Java.

For instance let's say I have xml like this:

        <root xmlns="urn:test">
          <some-child>
            <name>Tom</name>
          </some-child>
        </root>

If we describe XSD following way:

        <xs:schema elementFormDefault="qualified"
targetNamespace="urn:test" xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="name" type="xs:string"/>
          <xs:element name="root">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="some-child">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:any/>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:schema>

We "lost" the information that child of <some-child> can be <name>. Then
if we compile using JAXB:

        public interface RootType ...{
            test.RootType.SomeChildType getSomeChild();
            void setSomeChild(test.RootType.SomeChildType value);
            public interface SomeChildType {
                java.lang.Object getAny();
                void setAny(java.lang.Object value);
            }
        }

        public interface Name...
        {
            java.lang.String getValue();
            void setValue(java.lang.String value);
        }

And we "lost" the information that namespace was "urn:test" and
<some-child> had "-" part. Expression for JXPath will probably look like
this:

        //SomeChild[Any/Value="Tom"]

Which is not same as:

        //x:some-child[x:name="Tom"]

That works against real XML

Thanks,
Gia

> -----Original Message-----
> From: Aleksei Valikov [mailto:valikov_at_gmx.net]
> Sent: Thursday, May 06, 2004 1:37 AM
> To: users_at_jaxb.dev.java.net
> Subject: Re: JAXB and JXPath
>
> Hi.
>
> > Unfortunately JXPath/JAXB can't be expected to behave same way as
> > XPathAPI/DOM except for very small subset of possible xml documents.
>
> Like Germans say, jaein, yes and no.
> I could not figure out from the JXPath documentation, exactly
> which subset of the XPath is supported, but I guess, XML and
> order-specific axis may misbehave, give "wrong" results.
> However, child:: axis, ordering in the lists, simple
> predicates and simple functions like count(...) will work.
> It is true, that supported subset of the language is not
> large. However, in practice this subset covers more than half
> of the cases.
>
> The trick with JXPath looks nice, but I'm a bit confused
> about the usage scenarios. Great for unit tests, but what else?
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net