[DDI-users] XMLBeans Tools for DDI3.0

Sandfort, Michael Michael.Sandfort at usdoj.gov
Wed Sep 2 12:08:11 EDT 2009


Hello,

I'm trying to use the XMLBeans tools for DDI3.0 provided at http://opendatafoundation.org/?lvl1=forge, but I'm running
into some problems and have a few questions:

1) I'm assuming the tools are the compiled DDI3.0 schema, compiled through something like the "scomp" function
which comes with the XMLBeans package. Is that correct? Is there an ant script which might allow me to do this on my own?
The XMLBeans help pages have a small section on compiling schemas with dependencies, but the dependency map for
the DDI *.xsd files is not provided anywhere I can find in the user manuals.

2) I've had success with the code snippet below in generating the interface to DDIInstance by parsing the XML. But after the interface is
created, I can't seem to find any of the methods (e.g., addNewFoo()) which the XMLBeans help pages suggest should be available
in a compiled schema. I've had similar problems trying to use the cursor interface to add elements, and also in getting XMLBeans
to understand the complicated namespace prefix structure of DDI3.0.

3) The XMLBeans help pages talk about how to add elements using the generated interface (particles ending in ...Type),
but many of the critical objects defined in the compiled schema are Documents rather than Types. There doesn't seem to be
anything in the documentation describing how to generate
<ddi:DDIInstance ...>
	<s:StudyUnit></s:StudyUnit>
</ddi:DDIInstance>
from org.ddialliance.ddi_3_0.xml.xmlbeans.studyunit.StudyUnitDocument.

Any help would be most appreciated.

Thanks!
Mike Sandfort

-----------------------
import java.io.*;
import org.apache.xmlbeans.*;
import org.ddialliance.ddi_3_0.xml.xmlbeans.instance.*;
import org.ddialliance.ddi_3_0.xml.xmlbeans.studyunit.*;
import org.ddialliance.ddi_3_0.xml.xmlbeans.reusable.*;

public class Example
{
	public static void main(String[] args)
	{
		File ddiXmlFile = new File(args[0]);
		String updatedDdiXml = addSection(ddiXmlFile);
		System.out.println(updateDdiXml);
	}

	private static String addSection(File ddiInstance)
	{
		DDIInstanceDocument ddiDoc = null;
		try
		{
			ddiDoc = DDIInstanceDocument.Factory.parse(ddiInstance);
		} catch (XmlException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		}

		StudyUnitDocument newStudyDoc = StudyUnitDocument.Factory.newInstance();
		CitationType newCitation = CitationType.Factory.newInstance();

		return ddiDoc.toString();
	}
}

The above compiles and will print a valid DDI instance testFile.xml to the screen. But any attempt to add
the citation to the study unit via addNewCitation() or addNewCitationType() fails with method not recognized.
Similarly, any attempt to add a study unit to the instance fails.	



More information about the DDI-users mailing list