You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by Ronny Priv <ro...@gmx.de> on 2008/06/13 10:05:12 UTC

XmlSchema: How to remove an element?

Hello,

I've got problems removing a certain element from a schema.

I tried the following code and an item seems to be removed from the schema but it is not the correct one. So I'm wondering if it is a bug or am I doing something wrong here?

XmlSchemaObjectTable elements = schema.getElements();
XmlSchemaObject wrongElement = elements.getItem(elementName);
schema.getItems().remove(wrongElement);

thanks
ronny
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: XmlSchema: How to remove an element?

Posted by Ronny Priv <ro...@gmx.de>.
Yes, it's a QName and there is only one such element in the schema.

At the moment I use this quick hack with "removeAt(i)" and without "equals"-call for removing elements, but it doesn't feel so good.

for (int i = 0; i < schema.getItems().getCount(); i++) {
            XmlSchemaObject schemaObject = schema.getItems().getItem(i);
            if (schemaObject instanceof XmlSchemaElement)
            {
                
                XmlSchemaElement schemaElement = (XmlSchemaElement) schemaObject;
                if (!acceptableElements.contains(schemaElement.getQName().getLocalPart())) {
                    //Achtung, schema.getItems().remove(wrongElement) funktioniert nicht
                    //und loescht irgendein element
                    schema.getItems().removeAt(i);
                    //indices have changed
                    i--;
                }
                
            }
        }

regards
ronny

-------- Original-Nachricht --------
> What is the elementName here ? Is it the QName for an element ?

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

Re: XmlSchema: How to remove an element?

Posted by Ajith Ranabahu <aj...@gmail.com>.
What is the elementName here ? Is it the QName for an element ?

On Fri, Jun 13, 2008 at 4:05 AM, Ronny Priv <ro...@gmx.de> wrote:
> Hello,
>
> I've got problems removing a certain element from a schema.
>
> I tried the following code and an item seems to be removed from the schema but it is not the correct one. So I'm wondering if it is a bug or am I doing something wrong here?
>
> XmlSchemaObjectTable elements = schema.getElements();
> XmlSchemaObject wrongElement = elements.getItem(elementName);
> schema.getItems().remove(wrongElement);
>
> thanks
> ronny
> --
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>



-- 
Ajith Ranabahu

Reading, after a certain age, diverts the mind too much from its
creative pursuits. Any man who reads too much and uses his own brain
too little falls into lazy habits of thinking - Albert Einstein