Ejemplo n.º 1
0
# Create a Parser of specified format
format = sys.argv[2]
builder = ChannelBuilder()
if format == "0.91":
    parser = RSS_0_91_Parser(builder)
else:
    parser = RSS_1_0_Parser(builder)

# Read in Channel from File
channel = parser.parse(File(filename).toURL())

# Create a File to marshal to
writer = FileWriter("test-persist-channel.xml")

# Load the mapping information from the file
mapping = Mapping()
mapping.loadMapping("../../src/de/nava/informa/impl/jdo/mapping.xml")

# Marshal the channel object
marshaller = Marshaller(writer)
marshaller.setMapping(mapping)
marshaller.marshal(channel)

# ---- Unmarshalling

# Create a Reader to the file to unmarshal from
# reader = FileReader("test-persist-channel.xml")

# Unmarshal the channel object
# channel = Unmarshaller.unmarshal(Channel.class, reader);
from org.exolab.castor.mapping import Mapping
from org.exolab.castor.xml import Marshaller

# -- Define the JDO object
jdo = JDO()
jdo.setDatabaseName("jdoinforma")
jdo.setConfiguration("../../src/de/nava/informa/impl/jdo/database.xml")
db = jdo.getDatabase()

# -- Create a File to marshal to
writer = FileWriter("test-channels.xml")

# -- Load the mapping file
mapping = Mapping()
mapping.loadMapping("../../src/de/nava/informa/impl/jdo/mapping.xml")

# -- prepare XML marshalling
marshaller = Marshaller(writer)
marshaller.setMapping(mapping)

# -- write out all channels in the database
db.begin()
oql = db.getOQLQuery("SELECT c FROM de.nava.informa.impl.jdo.Channel c")
results = oql.execute()
while results.hasMore():
    marshaller.marshal(results.next())

db.commit()

db.close()