|
Castor-dev, Hello. I’m using Castor-XML 0.9.5.2 and I’m having an issue using
the <bind-xml location=””> feature.
I know that you don’t provide support, but if you do have a chance to look
at this issue I would appreciate it. I’m
not sure if it’s a bug or an error on my part.
I’ve attached the pertinent files.
Briefly, I’m getting the following error when unmarshaling
the XML file: org.xml.sax.SAXException: unable to
find FieldDescriptor for 'name' in ClassDescriptor of long-name The snippet of XML data is: <drugdata:drug
drug-id="36" orphan="no" who-formulary="no"> <drugdata:long-name> <drugdata:name>Acetaminophen; Chlorpheniramine Maleate; Hydrocodone Bitartrate; Phenylephrine Hydrochloride</drugdata:name> </drugdata:long-name> </drugdata:drug> And the snippet of the XML mapping file is: <class
name="com.elsevier.mdc.dao.Drug"
auto-complete="true"> <map-to
xml="drug" ns-prefix="drugdata"/> <field
name="longName" type="java.lang.String"> <bind-xml
name="name" node="element"
location="long-name"/> </field> </class> I think this should be easy, but I’ve not
been able to determine the solution. If
I change the name of the <drugdata:name> tag to simply <name>, then
it works, but obviously I can’t do that.
What am I missing in respect to declaring namespaces, so the “location”
feature can recognize that <drugdata:long-name> contains a field called
<drugdata:name>? Here’s most of the Java code: public class MDCImportIBN {
public MDCImportIBN() { }
public static void main(String args[]) {
Mapping mapping = new
Mapping();
try {
// 1. Load the mapping information from the file
mapping.loadMapping( "ibnmapping.xml" );
// 2. Unmarshal the data
Unmarshaller unmar = new Unmarshaller(mapping);
ExportContainer exportContainer = (ExportContainer)unmar.unmarshal(new
InputSource(new FileReader("c:/mdc/xml/IBN/d000036.xml")));
// 3. Do some processing on the data
// 4. marshal the data with the changes and print the XML in the console
Marshaller marshaller = new Marshaller(new
OutputStreamWriter(System.out));
marshaller.setMapping(mapping);
marshaller.marshal(exportContainer); }
catch (Exception e) {
System.out.println(e);
return; } } } Thanks, Matt ---
---
|
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd"><mapping> <class name="com.elsevier.mdc.ExportContainer" auto-complete="true"> <map-to xml="export-container" ns-prefix="drugdata"/> <field name="DatabaseExtract" type="com.elsevier.mdc.DatabaseExtract"> <bind-xml name="database-extract"/> </field> </class> <class name="com.elsevier.mdc.DatabaseExtract" auto-complete="true"> <map-to xml="database-extract" ns-prefix="drugdata"/> <field name="Drug" type="com.elsevier.mdc.dao.Drug"> <bind-xml name="drug"/> </field> </class> <class name="com.elsevier.mdc.dao.Drug" auto-complete="true"> <map-to xml="drug" ns-prefix="drugdata"/> <field name="id" type="java.lang.Integer"> <bind-xml name="drug-id" node="attribute"/> </field> <field name="orphanDrug" type="java.lang.Boolean"> <bind-xml name="orphan" node="attribute"/> </field> <field name="whoFormulary" type="java.lang.Boolean"> <bind-xml name="who-formulary" node="attribute"/> </field> <field name="longName" type="java.lang.String"> <bind-xml name="name" node="element" location="long-name"/> </field> </class> </mapping>
package com.elsevier.mdc;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.Marshaller;
import java.io.IOException;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import org.xml.sax.InputSource;
/**
* <p>Title: com.elsevier.mdc</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: JSN Consulting</p>
* @author Matthew Clemmer
* @version 1.0
*/
public class MDCImportIBN {
public MDCImportIBN() {
}
public static void main(String args[]) {
Mapping mapping = new Mapping();
try {
// 1. Load the mapping information from the file
mapping.loadMapping( "ibnmapping.xml" );
// 2. Unmarshal the data
Unmarshaller unmar = new Unmarshaller(mapping);
ExportContainer exportContainer = (ExportContainer)unmar.unmarshal(new InputSource(new FileReader("c:/mdc/xml/IBN/d000036.xml")));
// 3. Do some processing on the data
// 4. marshal the data with the changes and print the XML in the console
Marshaller marshaller = new Marshaller(new OutputStreamWriter(System.out));
marshaller.setMapping(mapping);
marshaller.marshal(exportContainer);
} catch (Exception e) {
System.out.println(e);
return;
}
}
}<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE drugdata:export-container PUBLIC "-//ES//DTD drug data and documents DTD version 1.1//EN//XML" "file:///c:/mdc/dtds/drugsexport.dtd"> <drugdata:export-container xmlns:drugdata="http://www.elsevier.com/xml/common/drug-database/dtd" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:de="http://www.elsevier.com/xml/common/drug-document/dtd"> <drugdata:database-extract> <drugdata:drug drug-id="36" orphan="no" who-formulary="no"> <drugdata:long-name> <drugdata:name>Acetaminophen; Chlorpheniramine Maleate; Hydrocodone Bitartrate; Phenylephrine Hydrochloride</drugdata:name> </drugdata:long-name> </drugdata:drug> </drugdata:database-extract> </drugdata:export-container>
