You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Nathaniel Auvil <na...@gmail.com> on 2006/02/24 21:20:21 UTC

[1.2.1] Xmlbeans Performance Boost

Hi. I have added a major performance improvement to the XMLBeanSerializer
Class that has made its way around the lists.  We saw the performance for
large documents (>7MB) drop from 106 seconds to 8 seconds!  With smaller
improvements for smaller documents.  Here is the updated Serialize method:


    public void serialize( QName name, Attributes attributes, Object value,
SerializationContext context ) throws IOException
    {
        if( !(value instanceof XmlObject) )
        {
            throw new IOException( ((value != null) ?
value.getClass().getName()
: "null") + " is not an " + XmlObject.class.getName() );
        }
        else
        {
            context.setWriteXMLType( null );


            XmlObject xmlObject= (XmlObject) value;

            XmlOptions xmlOptions= new XmlOptions();
            xmlOptions.setSaveSyntheticDocumentElement( name );
            context.writeString( xmlObject.xmlText( xmlOptions ) );


            /**************
            //---this is SLLLLOOOOWWWWW on very large xml documents

                context.startElement( name, attributes );

                XmlCursor xCur = ((XmlObject) value).newCursor();
                if( xCur.toFirstContentToken() == XmlCursor.TokenType.START)
                {
                    do
                    {
                        Node n = xCur.getDomNode();
                        if( n.getNodeType() == Node.ELEMENT_NODE )
                        {
                            context.writeDOMElement( (Element) n );
                        }
                    }
                    while( xCur.toNextSibling() );
                }
                context.endElement ();

            **************/
        }
    }