You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Luke Blanshard <lu...@quiq.com> on 2000/10/27 22:46:45 UTC

Two typos in Xerces-J 1.2.1

Hi all,

  I recently submitted 3 bugs against 1.2.0 to this list.  One of them
was fixed in 1.2.1 (thank you).  The other two are still present in
1.2.1.  Both of these are in the nature of typos rather than major
design flaws, but they are still honest-to-god bugs.

  First, in org.apache.xerces.validators.common.XMLValidator.  In the
callStartElement method, the fElementChildrenOffsetStack array needs to
be resized when the next index goes off the end of the array.  The
current test (on line 829) is:

         if (fElementChildrenOffsetStack.length < fElementDepth) {

The fElementDepth field is used a few lines later to index the array.
So in fact, this test is wrong---it should be a "<=" test rather than
"<":

         if (fElementChildrenOffsetStack.length <= fElementDepth) {


  The second bug is in org.apache.xerces.parsers.DOMParser.
(Whoops---I see my first bug report said it was in DocumentImpl.  Ouch.
Sorry.)  In the startDocument method, you test whether the document
class being used is a subclass of the default document class.  But this
test is backwards.  The current test (on line 936) is:

                if (docClass.isAssignableFrom(defaultDocClass)) {

but it should be:

                if (defaultDocClass.isAssignableFrom(docClass)) {

(This only manifests itself if you replace the document class with a
subclass of DocumentImpl, which I did.  With the test as it is, the
fDocumentImpl field remains unused unless the document class is exactly
DocumentImpl.)


  Many thanks in advance.

Cheers,
Luke


Re: complexType children question

Posted by Jerry Lawson <je...@virtualsummit.com>.
Eric,
I pretty much understand. If I don't use elementFormDefault
(at schema decl) or form (at element decl), I have to change
my xmlns="uri" to xmlns:tgt="uri" in the instance document.
In addition, I have to use the prefix to qualify those elements,
including the root element.
Adding the prefix seems to be more work than simply using
elementFormDefault, so I would think elementFormDefault is
the ``typical'' way to go for this type of problem.

thanks for the xml lesson.

Eric Ye wrote:
> 
> I can tell your schema has a targetNamespace defined, and in your xml file,
> you have a ns binding like xmlns = "your target ns uri".
> 
> To answer your question, NO, you don't have to use elementFormDefault =
> "qualified" to make it work right, but you can't use the default namespace
> prefix in this case e.g., if you change your example like the following, it
> will work:
> 
>    <.... xmlns:tgt = "your target ns uri" ...>
>       <tgt:Addresses>
>            <address> 123 main st </address>
>       </tgt:Address>
> 
> See the point? if you use the default ns prefix xmlns="your target ns uri"
> in your instance xml file, every element's unprefixed name, e.g. both
> "Addresses" and "address",  within the scope of this binding will be
> expanded as a qualified name, i.e. ["your targe ns uri", "Addresses"] and
> ["your targe ns uri", "address"].  However, in your schema, you declared
> <address> element as a locally scope element with an UNQUALIFIED name
> because you don't have elementFormDefault = "qualified" for the whole
> schema,  or form="qualified" for this element decl, a unqualified name is
> simply a name with no namespace, when expanded, it will be [null,
> "address"], that is why the validator can't match them properly.
> 
> _____
> 
> Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
> 
> ----- Original Message -----
> From: "Jerry Lawson" <je...@virtualsummit.com>
> To: <xe...@xml.apache.org>
> Sent: Friday, October 27, 2000 2:40 PM
> Subject: complexType children question
> 
> > If I have something like this in my schema:
> >
> > <element name="Addresses"
> >  <complexType content="elementOnly">
> >    <element name="address" type="string" minOccurs="1"/>
> >  </complexType>
> > </element>
> >
> > and my instance doc has:
> >
> > <Addresses>
> >   <address>123 main st</address>
> > </Addresses>
> >
> > xerces 1.2.1 XMLValidator generates and exception:
> >   ``Element type "address" must be declared.''
> >
> > With debugs enabled, I've tracked it down to TraverseSchema
> > doesn't know the uriIndex of element "address" in the
> > schema, **unless** I add
> >  elementFormDefault="qualified"
> > to the <schema declaration.
> >
> > My question is: what is the proper way to define the namespace
> > of the subelement in this case, without using the
> > elementFormDefault attribute ?
> >
> > thanks for any help -<:O
> > --
> > ___________________________________________________
> > Jerry Lawson                   Virtual Summit, Inc.
> > Virtual Programmer   jerry.lawson@virtualsummit.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

-- 
___________________________________________________
Jerry Lawson                   Virtual Summit, Inc.
Virtual Programmer   jerry.lawson@virtualsummit.com

Re: complexType children question

Posted by Eric Ye <er...@locus.apache.org>.
I can tell your schema has a targetNamespace defined, and in your xml file,
you have a ns binding like xmlns = "your target ns uri".

To answer your question, NO, you don't have to use elementFormDefault =
"qualified" to make it work right, but you can't use the default namespace
prefix in this case e.g., if you change your example like the following, it
will work:

   <.... xmlns:tgt = "your target ns uri" ...>
      <tgt:Addresses>
           <address> 123 main st </address>
      </tgt:Address>

See the point? if you use the default ns prefix xmlns="your target ns uri"
in your instance xml file, every element's unprefixed name, e.g. both
"Addresses" and "address",  within the scope of this binding will be
expanded as a qualified name, i.e. ["your targe ns uri", "Addresses"] and
["your targe ns uri", "address"].  However, in your schema, you declared
<address> element as a locally scope element with an UNQUALIFIED name
because you don't have elementFormDefault = "qualified" for the whole
schema,  or form="qualified" for this element decl, a unqualified name is
simply a name with no namespace, when expanded, it will be [null,
"address"], that is why the validator can't match them properly.

_____


Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org

----- Original Message -----
From: "Jerry Lawson" <je...@virtualsummit.com>
To: <xe...@xml.apache.org>
Sent: Friday, October 27, 2000 2:40 PM
Subject: complexType children question


> If I have something like this in my schema:
>
> <element name="Addresses"
>  <complexType content="elementOnly">
>    <element name="address" type="string" minOccurs="1"/>
>  </complexType>
> </element>
>
> and my instance doc has:
>
> <Addresses>
>   <address>123 main st</address>
> </Addresses>
>
> xerces 1.2.1 XMLValidator generates and exception:
>   ``Element type "address" must be declared.''
>
> With debugs enabled, I've tracked it down to TraverseSchema
> doesn't know the uriIndex of element "address" in the
> schema, **unless** I add
>  elementFormDefault="qualified"
> to the <schema declaration.
>
> My question is: what is the proper way to define the namespace
> of the subelement in this case, without using the
> elementFormDefault attribute ?
>
> thanks for any help -<:O
> --
> ___________________________________________________
> Jerry Lawson                   Virtual Summit, Inc.
> Virtual Programmer   jerry.lawson@virtualsummit.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>


complexType children question

Posted by Jerry Lawson <je...@virtualsummit.com>.
If I have something like this in my schema:

<element name="Addresses"
 <complexType content="elementOnly">
   <element name="address" type="string" minOccurs="1"/>
 </complexType>
</element>

and my instance doc has:

<Addresses>
  <address>123 main st</address>
</Addresses>

xerces 1.2.1 XMLValidator generates and exception:
  ``Element type "address" must be declared.''

With debugs enabled, I've tracked it down to TraverseSchema
doesn't know the uriIndex of element "address" in the
schema, **unless** I add
 elementFormDefault="qualified"
to the <schema declaration.

My question is: what is the proper way to define the namespace
of the subelement in this case, without using the
elementFormDefault attribute ?

thanks for any help -<:O
-- 
___________________________________________________
Jerry Lawson                   Virtual Summit, Inc.
Virtual Programmer   jerry.lawson@virtualsummit.com

Re: Two typos in Xerces-J 1.2.1

Posted by Eric Ye <er...@locus.apache.org>.


> Hi all,
> 
>   I recently submitted 3 bugs against 1.2.0 to this list.  One of them
> was fixed in 1.2.1 (thank you).  The other two are still present in
> 1.2.1.  Both of these are in the nature of typos rather than major
> design flaws, but they are still honest-to-god bugs.
> 
>   First, in org.apache.xerces.validators.common.XMLValidator.  In the
> callStartElement method, the fElementChildrenOffsetStack array needs to
> be resized when the next index goes off the end of the array.  The
> current test (on line 829) is:
> 
>          if (fElementChildrenOffsetStack.length < fElementDepth) {
> 
> The fElementDepth field is used a few lines later to index the array.
> So in fact, this test is wrong---it should be a "<=" test rather than
> "<":
> 
>          if (fElementChildrenOffsetStack.length <= fElementDepth) {
> 

I've checked in your fix for XMLValidator.java, thanks for the contribution


_____


Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org