[jdom-interest] b7 problem

Sonya Pettit Sonya.Pettit at sas.com
Tue Jun 26 14:36:40 PDT 2001


I am having a problem with the b7 release against the same code that ran fine under b6.  I am creating a document from an input stream that I substring to get <OBJECTS> as the root element.  Later, I need to extract each child and build a new document for each.

	String newXML = xml.substring(xml.indexOf("<OBJECTS>"), xml.lastIndexOf("</OBJECTS>") + 10);
        SAXBuilder builder = new SAXBuilder(); 
		Vector v = new Vector();
		try {
			org.jdom.Document doc = builder.build(new StringReader(newXML));
			Element root = doc.getRootElement();
			if(root.hasChildren()) {
				java.util.List li;
				try{
					li = root.getChildren();
				}catch(NoSuchMethodError e) {
					throw e;
				}
				for(int i = 0; i < li.size(); i++) {
					Element newRoot = (Element)li.get(i);

// at the following line, I get an IllegalAddException.  It says:  "The element "PropertyGroup" could not be added as the root of the document:  the element already has an existing parent "OBJECTS"
					org.jdom.Document newDoc = new org.jdom.Document(newRoot);	
					MetadataObject mo = null;
					if(newRoot.getAttributeValue("UseType") == null || newRoot.getAttributeValue("UseType").equals(""))
						mo = getInstance(className);
					else mo = getInstance(newRoot.getAttributeValue("UseType"));
					Hashtable hash = new Hashtable();
					AttributeSetter as = new AttributeSetter(newDoc, mo, this, hash);
					v.add(mo);
				}
			}
		}catch(InstantiationException ie) {
			throw ie;
		}catch(JDOMException je) {
			throw new MetadataRuntimeException(je.getMessage());
		}

I assume there was a change made that will require me to remove the element from its parent before adding it to a new document.  Is this the case and if so is removeChild(String) the recommended way to go about it?
Thanks in advance,
Sonya Pettit





More information about the jdom-interest mailing list