Hello out there,
I have some questions about, how to inserting JDOM-Objects from servlets into the database. First I created a JDOM-Object:
import org.jdom.*;
Document mydoc = new Document ( new Element ("Anwender") );
Element root = mydoc.getRootElement();
Element erstesElement = new Element ("vorname").setText(vorname);
root.addContent( erstesElement );
Element zweitesElement = new Element ("nachname").setText(nachname);
root.addContent( zweitesElement );
Element drittesElement = new Element ("wohnort").setText(wohnort);
root.addContent( drittesElement );
Then I buildet a connection to a database ( this works, no need to dump here ) and a accessor-Object.
It doesn’t work you mean it can’t even compile? TXMLObjectAccessor.insert(TXMLObject)
Yes you should use a TXMLObject. Read it from a File, URL, Stream, Reader, etc. In the following example I get a TXMLObject instance and then read it from a stream(piped). Using this way I know for sure what model is used.
PipedInputStream pin=new PipedInputStream();
PipedOutputStream pout=new PipedOutputStream(pin);
//Write your document to pout using a thread....
TXMLObject xmlOb = TXMLObject.newInstance(TJDOMObjectModel.getInstance());
xmlOb.readFrom(pin);
//Remember to close streams
The wrong thing about the API4J is that all the documents always come from a stream or similar. So doesn’t matter wich technique you use to build your document, you should also care about TXMLObjectModel. It doesn’t reuse your data.
Can some one explain big differences using different XMLObjectModels and consecuences on XMLObjects.
Document mydoc = new Document ( new Element ("Anwender") );
Element root = mydoc.getRootElement();
Element erstesElement = new Element ("vorname").setText(vorname);
root.addContent( erstesElement );
Element zweitesElement = new Element ("nachname").setText(nachname);
root.addContent( zweitesElement );
Element drittesElement = new Element ("wohnort").setText(wohnort);
root.addContent( drittesElement );
then created a TXMLObject and fill it with the JDOM.
I haven’t found a way to do so. As I say that’s one of the bad things in the API4J in Tamino. There is no way to access the underlaying Stream,DOM,JDOM behind the XMLObject.
XMLObject is only for the transaction not for data manupulating.
I just discover that you can ‘reuse’ your DOM or JDOM. There’s a way to create a TXMLObject. I don’t know if you can still edit the JDOM or DOM, in fact I think no.
Use Method TXMLObject.newInstance(Object object)
As described in JavaDoc
Factory method, creates a TXMLObject instance from the given object instance. The type of the input object determines the object model for the TXMLObject instance returned. For example, if the input object is an instance of org.w3c.dom.Element or org.w3c.dom.Document, the DOM object model is taken. If the input element is an instance of org.jdom.Element or org.jdom.Document, the JDOM object model is taken. The XML content of the input object is taken as the XML content of the TXMLObject instance.
Parameters:
object - an object representing the XML document.
Returns:
TXMLObject that wraps the given object.