There is a bug where when you compare namespaces, the underlying code
does == instead of .equals().  I fixed it with some code like this:

m_grammar=loadGrammar();

m_model=m_grammar.toXSModel();
// This is a nasty bug in xerces.  I suspect that somewhere under the
// covers it is doing an equality test using == instead of .equals().
for (int i=0;i<m_model.getNamespaces().getLength();i++)
{
        //System.out.println(i + ":" + m_model.getNamespaces().item(i));
        if (m_model.getNamespaces().item(i).equals(m_typeNamespace))
        {
                m_typeNamespace = m_model.getNamespaces().item(i);
        }
}

This may be what you are encountering.  If the namespaces contain the
same string, I force my internal one to a reference to the same string
instance as xerces will use internally.  Nasty, but it will work until
the fix gets rolled out in the next release.

-----Original Message-----
From: Stanimir Stamenkov [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 25, 2004 5:14 AM
To: Xerces-J User
Subject: [XML Schema API] XSModel.getComponentsByNamespace() problem

Hello,

I've faced the following problem: The 
'XSModel.getComponentsByNamespace()' method simply doesn't work for 
me. I've tried pretty simple example:

-----"simple.xsd"
<?xml version="1.0" encoding="US-ASCII" ?>

<xs:schema
     xmlns="http://www.geocities.com/stanio/otherthing";
     xmlns:xs="http://www.w3.org/2001/XMLSchema";
     targetNamespace="http://www.geocities.com/stanio/otherthing";>

   <xs:element name="info">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="title" type="xs:string" />
         <xs:element name="description"
             minOccurs="0" type="xs:string" />
       </xs:sequence>
     </xs:complexType>
   </xs:element>

</xs:schema>
-----"simple.xsd"--

I've set the default namespace for the schema document to match the 
'targetNamespace' although I'm not sure I need it (I've tried it 
both ways - with and without it).

A call to 'XSModel.getComponents(XSConstants.ELEMENT_DECLARATION)' 
returns an 'XSNamedMap' which contains the "info" element 
declaration. However if I call:

XSModel.getComponentsByNamespace(XSConstants.ELEMENT_DECLARATION,
         "http://www.geocities.com/stanio/otherthing";);

I get a 'null' result although the API doc specifies it should 
return an empty map even if it didn't find matching element. But the 
real problem is that it doesn't find the matching element - "info". 
Is this a know issue?

FWIW, If I don't use 'targetNamespace' and try:

XSModel.getComponentsByNamespace(XSConstants.ELEMENT_DECLARATION,
                                  null);

I get a "positive" result.

-- 
Stanimir


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to