[jdom-interest] RE: Request new method Element.addContent( List mixedContent ).

Steven D. Keens skeens at planetfred.com
Thu Mar 29 11:34:08 PST 2001

Yes, it is a good way but for speed it looks to be slow.

Also, getMixedContent() copies all the mixed content
into a PartialList then returns that.  Or am I missing something?

It also allows me to add objects that aren't
Elements, PI's, Strings, Comments, CDATA's, & Entity's.

If you try the code below I get one of two results
depending on if the line e.addContent( l ) is commented out.
Note that this uses the addContent( List ) I sent earlier.

1) Result when e.addContent( l ) is commented out.

	<?xml version="1.0" encoding="UTF-8"?>

   Notice that the 5 and test objects aren't outputted.
   I didn't find where the logic is for this but why should
   I have to do it in two places.

2) Result when e.addContent( l ) is allowed to run.

	An Element may directly contain only objects of type
	String, Element, Comment, CDATA, Entity, and
	ProcessingInstruction: java.lang.Integer is not allowed

import org.jdom.*;
import org.jdom.output.*;
import java.util.*;
import java.io.*;

public class test
    public static void main(String[] args)
            // Build the root element and document.
            Element e = new Element( "root" );
            Document d = new Document( e );

            LinkedList l = new LinkedList();
            l.add( new Integer( 5 ) );
            l.add( "Steven" );
            l.add( new test() );

            // This line works and passes through OK.
            e.getMixedContent().addAll( l );

            // This line throws an exception.
            e.addContent( l );

	    // If you comment out the e.addContent( l ) line just above
	    // the XMLOutputter works fine but doesn't show the
	    // Integer(5) nor the test object added to the linked list.
            XMLOutputter outer = new XMLOutputter( "  ", true );
            outer.output( d, System.out );
        catch( Exception e )
            System.out.println( e.getMessage() );

>-----Original Message-----
>From: jdom-interest-admin at jdom.org
>[mailto:jdom-interest-admin at jdom.org]On Behalf Of Jason Hunter
>Sent: Thursday, March 29, 2001 12:33
>To: Steven D. Keens
>Cc: jdom-interest
>Subject: Re: [jdom-interest] RE: Request new method Element.addContent(
>List mixedContent ).
>The standard way to do it now is:
>Isn't that pretty good already?

Steven Keens                mailto:skeens at planetfred.com
PlanetFred Inc.             http://www.planetfred.com
44 Byward Market, Suite 240, Ottawa, ON, K1N 7A2, Canada

More information about the jdom-interest mailing list