tags:

views:

317

answers:

3

So here's the scenario...I have an XSD file describing all the objects that I need. I can create the objects in Java using JAXB no problem. I have an XML/RDF file that I need to parse into those objects.

What is the EASIEST way to do this?

I have been looking into Jena and have played around with it, but can't see how to easily map the XML/RDF file to the XSD objects that were generated. Here is a snippet of the XSD file as well as the XML/RDF file:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:a="http://langdale.com.au/2005/Message#" 
    xmlns:sawsdl="http://www.w3.org/ns/sawsdl" 
    targetNamespace="http://iec.ch/TC57/2007/profile#" 
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified" 
    xmlns="http://langdale.com.au/2005/Message#" 
    xmlns:m="http://iec.ch/TC57/2007/profile#"&gt;
<xs:annotation/>
<xs:element name="Profile" type="m:Profile"/>
<xs:complexType name="Profile">
<xs:sequence>
<xs:element name="Breaker" type="m:Breaker" minOccurs="0" maxOccurs="unbounded"/>

And the XML/RDF:

<!-- CIM XML Output For switch783:(295854688) -->
<cim:Switch rdf:ID="Switch_295854688">
    <cim:IdentifiedObject.mRID>Switch_295854688</cim:IdentifiedObject.mRID>
    <cim:IdentifiedObject.aliasName>Switch_295854688</cim:IdentifiedObject.aliasName>
    <cim:ConductingEquipment.phases 
        rdf:resource="http://iec.ch/TC57/2009/CIM-schema-cim14#PhaseCode.ABC" />
    <cim:Switch.circuit2>0001406</cim:Switch.circuit2>
    <cim:Equipment.Line rdf:resource="#Line_0001406" />
A: 

Do the Resource/Subject/etc objects not have any methods for converting to DOM Element? Alternatively (not the neatest solution for sure) what about serializing to string and reading the string then using the JAXB-created (from XSD) objects' setter methods??

+1  A: 

What isn't clear from your post is any mapping between the XSD components and the particular resource data you have in RDF (or schema thereof, such as RDFS or OWL, or both). If you understand this mapping, then given you have a JAXB implementation to create Java objects already (with a view to populate them with the data represented as RDF) and a Jena implementation to parse the RDF/XML in Java, then I suggest that you can implement a Java 'bridge' - effectively custom code that queries the Jena model of the RDF data to map it into new objects of the classes as generated by JAXB, which can then be marshaled to the required XML.

If you'd rather not write any Java code at all to do this, you could write some XSLT or XQuery to transform your RDF/XML directly into the required XML, but this sounds like it will be more work than the aforementioned option given what you've got already.

sharky
+1  A: 

You could iterate through the RDF statements and populate your JAXB beans via a Bean population utility like BeanUtils.

Iterate the statements in such a form that statements with the same subject are processed in a group. The rdf:type statements define which Class to instantiate and the rest can be probably mapped to properties of the created beans.

If you are familiar with Java reflection then this is probably quite straightforward.

Timo Westkämper