Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [emf-dev] deserializing partial xml document into eobject


Donald,

Please use the newsgroup for questions.  

I don't think you should be using OPTION_XML_MAP; just the options used by the XML processor should be sufficient.  Probably SummarySegment corresponds to a local element declaration and so it won't be recognized at the root of a document, which expects to match against a global element declaration.  So if you defined a schema will null namespace and with the same type as the SummarySegment local element declaration then with that schema registered against the null namespace you should be able to get this to work; use Mpeg7XMLProcessor.getExtendedMetaData().putPackage(null, <the-package-for-the-summary-segment schema.>) to register that additional package against the null namespace.


Ed Merks/Toronto/IBM@IBMCA
mailto: merks@xxxxxxxxxx
905-413-3265  (t/l 969)




Donald Averill <ave@xxxxxxxxxxxxxxxx>
Sent by: emf-dev-bounces@xxxxxxxxxxx

05/19/2006 05:05 PM

Please respond to
Eclipse Modelling Framework

To
emf-dev@xxxxxxxxxxx
cc
Subject
[emf-dev] deserializing partial xml document into eobject





Hi,
I successfully created an EMF model from a schema and am able to load my
xml files into the model.  What I want to do is to deserialize part of
the document into its corresponding generated EObject.  The schema I
used to generate the model is the Mpeg7 schema
(http://m7itb.nist.gov/M7Validation.html).  For example, I can load the
following file no problem:

<?xml version="1.0" encoding="iso-8859-1"?>
<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001"
xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">
<Description xsi:type="SummaryDescriptionType">
<Summarization>
<Header xsi:type="DescriptionMetadataType">
<LastUpdate>2006-03-28</LastUpdate>
<Comment><FreeTextAnnotation>Summarization of a Dive based on Event log
and associated frame grabs</FreeTextAnnotation></Comment>
<Creator>
<Role href=""> <Agent xsi:type="PersonType">
<Name><GivenName>First</GivenName><FamilyName>Last</FamilyName></Name>
<Affiliation><Organization><Name>Organization
Name</Name></Organization></Affiliation>
</Agent>
</Creator>
<Instrument>
<Tool><Name>XSL Transform</Name></Tool></Instrument>
</Header>
<Summary hierarchy="independent" components="keyFrames keyThemes"
xsi:type="HierarchicalSummaryType">
<SourceID>J2-171</SourceID>
<SummaryThemeList>
<SummaryTheme id="EVT">Events manually annotated by
operators.</SummaryTheme>
<SummaryTheme id="ASNAP">Events automatically registered by software.  
No textual annotation</SummaryTheme>
</SummaryThemeList>
<SummarySegmentGroup level="0" themeIDs="EVT ASNAP" id="summary-J2-171">
<Name>Events for Dive J2-171</Name>
<Caption>Events captured by SD cameras</Caption>
    <SummarySegment themeIDs="EVT">
<Header xsi:type="DescriptionMetadataType">
<CreationLocation>
<GeographicPosition>
<Point altitude="-1.328" latitude="49.44816468" longitude="-128.89364908"/>
</GeographicPosition>
</CreationLocation>
</Header>
<Name>Light elevator in water (Vvan)</Name>
<KeyFrame>
<MediaUri>SubSea1.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea2.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea3.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea4.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
</SummarySegment>
<SummarySegment>
.......
</SummarySegment>
</SummarySegmentGroup>
</Summary>
</Summarization>
</Description>
</Mpeg7>

There are actually several thousand SummarySegment's.  When I load the
whole file, everything works fine.  But what I really want to do is to
take one of the SummarySegments and deserialize it into its
corresponding EObject.  In my case, it's called SummarySegmentType.  I
want to do this because I retrieve a select number of the
SummarySegments from an xml database (based on search) and I don't want
to have to return the whole document to get just the part I'm interested
in.  Basically, I want to have a SummarySegmentType object that was been
created from something like:

<SummarySegment xmlns="urn:mpeg:mpeg7:schema:2001" themeIDs="ASNAP">
<Header xsi:type="DescriptionMetadataType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CreationLocation>
<GeographicPosition>
<Point altitude="-2198.128" latitude="47.95012874"
longitude="-129.09741143"/>
</GeographicPosition>
</CreationLocation>
</Header>
<KeyFrame>
<MediaUri>SubSea1.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea2.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea3.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea4.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
</SummarySegment>

I have tried:

           Mpeg7XMLProcessor processor = new Mpeg7XMLProcessor();
           Map options = new HashMap();
           XMLResource.XMLMap xmlMap = new XMLMapImpl();
           // xmlMap.setNoNamespacePackage(Mpeg7Package.eINSTANCE);
           options.put(XMLResource.OPTION_XML_MAP, xmlMap);
           processor.load(new FileInputStream(new File("C:/test.xml")),
options);
         
and

           Mpeg7ResourceImpl resource = new
Mpeg7ResourceImpl(URI.createFileURI(f.getAbsolutePath()));
           XMLResource.XMLMap xmlMap = new XMLMapImpl();
           xmlMap.setNoNamespacePackage(Mpeg7Package.eINSTANCE);
           Map options = new HashMap();
           options.put(XMLResource.OPTION_XML_MAP, xmlMap);
           
options.put(XMLResource.OPTION_EXTENDED_META_DATA,ExtendedMetaData.INSTANCE);
           resource.load(options);

Both produce the following error:

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Class
'SummarySegment' not found. (file:/C:/test.xml, 1, 112)
   at
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:80)
   at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:189)
   at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:179)
   at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1089)
   at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:895)
   at edu.washington.cev.jasonii.Test.test2(Test.java:101)
   at edu.washington.cev.jasonii.Test.main(Test.java:33)
Caused by: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class
'SummarySegment' not found. (file:/C:/test.xml, 1, 112)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:1977)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1618)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createDocumentRoot(XMLHandler.java:1224)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1152)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1234)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:872)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:854)
   at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:626)
   at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
   at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:798)
   at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:878)
   at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(XMLDocumentScannerImpl.java:1157)
   at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
   at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
   at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
   at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
   at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
   at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
   at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
   at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:179)
   ... 5 more

Any help is appreciated.


_______________________________________________
emf-dev mailing list
emf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/emf-dev


Back to the top