(I posted this on Friday but never saw it make the list, so sorry if this is a duplicate)

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.setSaveSyntheticDocu
mentElement( 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 ();
           
            **************/
        }
    }

Reply via email to