Java API

MPEG-7 Binding for Java with XMLBeans

XMLBeans can be used to generate a Java API for working with MPEG-7 documents. This howto explains briefly the required software and how to use the generated API.

Required Software

  • XMLBeans 2.2.0: xmlbeans.apache.org
  • Saxon-B version 8.6.1 for (untyped) XPath/XQuery support. To download Saxon, go to sourceforge.net/projects/saxon, click the “download” link and then choose Saxon 8.6.1 from the list of files.
  • Install XMLBeans as described on the website.
  • for Saxon, add saxon8.jar, saxon8-dom.jar and xbean_xpath.jar to the classpath

MPEG-7 Schema Compilation

For compilation of the MPEG-7 Schema use the scomp tool from XMLBeans, for example:

scomp -out myMp7.jar mpeg7-2001.xsd

Using the Generated API

  • Add the following JARs to the classpath:
    xmlbeans-2.2.0/lib/xbean.jar xmlbeans-2.2.0/lib/xbean_xpath.jar xmlbeans-2.2.0/lib/jsr173_1.0_api.jar saxon8-6-1/saxon8.jar saxon8-6-1/saxon8-dom.jar myMp7.jar
  • Import the following packages/classes:
    mpegMpeg7Schema2001.* org.apache.xmlbeans.XmlCursor javax.xml.namespace.QName org.apache.xmlbeans.XmlObject
  • Instantiate the document
    Mpeg7Document myDoc = Mpeg7Document.Factory.newInstance();
  • Create the root element
    Mpeg7Document.Mpeg7 mp7 = myDoc.addNewMpeg7();
  • Set the namespace declarations
    XmlCursor c=mp7.newCursor();
    c.toFirstContentToken();
    c.insertNamespace(“”, “urn:mpeg:mpeg7:schema:2001”);
    c.insertNamespace(“mpeg7”, “urn:mpeg:mpeg7:schema:2001”);
    c.insertNamespace(“xsi”, “http://www.w3.org/2001/XMLSchema-instance”);
    c.insertAttributeWithValue(new QName(“http://www.w3.org/2001/XMLSchema-instance”,”schemaLocation”),”urn:mpeg:mpeg7:schema:2001 mpeg7-2001.xsd”);
    c.dispose();
  • Validate
    myDoc.validate();
  • Save
    mDoc.save(new java.io.File(“MyMp7File.xml”));
  • Load
    mDoc=Mpeg7Document.Factory.parse(new java.io.File(sFileName));

Troubleshooting

If you are using the XML Schema files provided on the NIST MPEG-7 Validation site, the following changes are necessary to make the compilation work:

  • audio-2001.xsd
    Line 741: SoundClassificationModelType: this is actually not a restriction, so replace the restriction by an extension
  • mds-2001.xsd
    There are 4 issues that all have the same cause: the same element names are used in various content groups so that it makes the content model ambiguous. In early versions there was a much simpler content (that does no exactly express the same semantics) which is valid, so we propose to replace the content of the following four types (the snippets given is the part below the extension element in each case):

    • Line 3919: EditedVideoEditingTemporalDecompositionType
      <sequence maxOccurs=”unbounded”>
      <choice>
      <choice>
      <element name=”Shot” type=”mpeg7:ShotType”/>
      <element name=”ShotRef” type=”mpeg7:ReferenceType”/>
      </choice>
      <choice>
      <element name=”GlobalTransition”   type=”mpeg7:GlobalTransitionType”/>
      <element name=”GlobalTransitionRef” type=”mpeg7:ReferenceType”/>
      </choice>
      </choice>
      </sequence>
    • Line 3994: ShotEditingTemporalDecompositionType
      <sequence maxOccurs=”unbounded”>
      <choice>
      <choice>
      <element name=”CompositionShot” type=”mpeg7:CompositionShotType”/>
      <element name=”CompositionShotRef” type=”mpeg7:ReferenceType”/>
      </choice>
      <choice>
      <element name=”CompositionTransition” type=”mpeg7:CompositionTransitionType”/>
      <element name=”CompositionTransitionRef” type=”mpeg7:ReferenceType”/>
      </choice>
      </choice>
      </sequence>
    • Line 4060: CompositionShotEditingTemporalDecompositionType
      <sequence maxOccurs=”unbounded”>
      <choice>
      <choice>
      <element name=”IntraCompositionShot” type=”mpeg7:IntraCompositionShotType”/>
      <element name=”IntraCompositionShotRef” type=”mpeg7:ReferenceType”/>
      </choice>
      <choice>
      <element name=”InternalTransition” type=”mpeg7:InternalTransitionType”/>
      <element name=”InternalTransitionRef” type=”mpeg7:ReferenceType”/>
      </choice>
      </choice>
      </sequence>
    • Line 4127: IntraCompositionShotEditingTemporalDecompositionType
      <sequence maxOccurs=”unbounded”>
      <choice>
      <choice>
      <element name=”IntraCompositionShot” type=”mpeg7:IntraCompositionShotType”/>
      <element name=”IntraCompositionShotRef” type=”mpeg7:ReferenceType”/>
      </choice>
      <choice>
      <element name=”InternalTransition” type=”mpeg7:InternalTransitionType”/>
      <element name=”InternalTransitionRef” type=”mpeg7:ReferenceType”/>
      </choice>
      </choice>
      </sequence>