[DDI-users] XMLBeans Tools for DDI3.0 (fwd)

Wendy Thomas wlt at pop.umn.edu
Wed Sep 2 14:29:38 EDT 2009


---------- Forwarded message ----------
Date: Wed, 2 Sep 2009 13:49:46 -0400
From: J Gager <j.b.gager at gmail.com>
To: Michael.Sandfort at usdoj.gov
Cc: 'Wendy Thomas' <wlt at pop.umn.edu>, 'Jannik Vestergaard Jensen' <jvj at dda.dk>,
     pascal.heus at gmail.com, 'Joachim Wackerow' <joachim.wackerow at gesis.org>
Subject: RE: [DDI-users] XMLBeans Tools for DDI3.0 (fwd)

Hi Mike -

Wendy Thomas forwarded this to me, and I think I can help you.

Yes, this jar was complied with the scomp utility from XMLBeans. We don't
have any script that would allow you to do this,
but you can run this from your command line. Just use the instance.xsd as
the schema to compile - it imports all other
schemas.

In order to add components, you need to move from the document level (which
represent global elements) down to the underlying
complex type. So for example, if you are parsing from a stub document as you
showed in your example, it would look like this:

 	ddiDoc = DDIInstanceDocument.Factory.parse(ddiInstance);
 	DDIInstanceType ddiit = ddiDoc.getDDIInstance();
 	StudyUnitType sut = ddiit.addNewStudyUnit();
 	CitationType newCitation = sut.addNewCitation();

Notice that I had to call the .getDDIInstance() method from the ddiDoc -
this gets the complex type to which content can
be added.

As far as the XXXDocuments are concerned - you only need to use these when
creating global elements (i.e. for you root
document, or when you need to create an element to be used in a
substitution). Outside of that, XMLBeans mainly deals
with the complex types.

Finally, regarding the cursor - is there a particular need you had to use
this, or were you just experimenting. The namespace
prefixes really shouldn't matter. The only thing that really matters are the
namespaces themselves. Prefixes are just a
convenience. If you have an example of what you were trying to do, I would
be happy to help you sort it out.

Good luck,

J Gager

---------- Forwarded message ----------
Date: Wed, 2 Sep 2009 12:08:11 -0400
From: "Sandfort, Michael" <Michael.Sandfort at usdoj.gov>
Reply-To: Data Documentation Initiative Users Group
<ddi-users at icpsr.umich.edu>
To: ddi-users at icpsr.umich.edu
Subject: [DDI-users] XMLBeans Tools for DDI3.0

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.

_______________________________________________
DDI-users mailing list
DDI-users at icpsr.umich.edu
http://www.icpsr.umich.edu/mailman/listinfo/ddi-users


More information about the DDI-users mailing list