[HELP] myDom,StringReader,TDOMObjectModel-problem

Hi to everybody,
i’m new and this is my first topic!
I’m just learning the tamino API for java and i’ve some problem[…of course! :)]
Before to begin i’m sorry for my english! be patient! :slight_smile:
Well…let’s start!
i’d like to understand how to pass a dom object to tamino!

i use this:

 import com.docuverse.dom.*;
 </pre><BR><BR>i create my dom document:<pre class="ip-ubbcode-code-pre">  //DOM:
	          BasicDocument doc = new BasicDocument();
	          //<TAG>
	          BasicElement TAuthor =new BasicElement(doc,"Author");
	          BasicElement TAuthorName=new BasicElement(doc,"AuthorName");
	          BasicElement TLivingPeriod=new BasicElement(doc,"LivingPeriod");
	          BasicElement TTitles =new BasicElement(doc,"Titles");
	 	  TAuthorName.appendChild(new BasicText(doc,aut.getAuthorName()));
		  TLivingPeriod.appendChild(new BasicText(doc,aut.getLivingPeriod()));
		  TAuthor.appendChild(TAuthorName);
		  TAuthor.appendChild(TLivingPeriod);
		  TAuthor.appendChild(TTitles);

 </pre><BR><BR>and then:<pre class="ip-ubbcode-code-pre">

	StringReader stringReader = new StringReader(TAuthor.toString());
	
	TXMLObject xmlObject = TXMLObject.newInstance(TDOMObjectModel.getInstance());
	xmlObject.readFrom(stringReader);
	TXMLObjectAccessor xmlObjectAccessor = tamino.newXMLObjectAccessor( TAccessLocation.newInstance( "Annales" ),TDOMObjectModel.getInstance());
	xmlObjectAccessor.insert(xmlObject);
	</pre><BR>my problem is:<BR>I don't want use the String reader! <BR><BR>In other topic i've read:<BR><pre class="ip-ubbcode-code-pre">TXMLObject xmlObject = TXMLObject.newInstance(myDomObject);



but it doesn’t work!or better…i don’tknow how to transform “myDOMDocument” into TDOMObjectModel!

let me know pls!
tnx

Hi Tobia,

Yes, you can insert a document into tamino collection without using StringReader.

Following piece of code will help you.

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.softwareag.tamino.db.API.accessor.TAccessLocation;
import com.softwareag.tamino.db.API.accessor.TXMLObjectAccessor;
import com.softwareag.tamino.db.API.connection.TConnection;
import com.softwareag.tamino.db.API.connection.TConnectionFactory;
import com.softwareag.tamino.db.API.objectModel.TXMLObject;
import com.softwareag.tamino.db.API.objectModel.dom.TDOMObjectModel;
import com.softwareag.tamino.db.API.response.TResponse;

public class TestTamino
{
//Tamino URI
private static final String URI = “http://localhost/tamino/mydb”;

public static void main(String args)
{
try
{

TConnection connection = null;
TConnectionFactory connectionFactory = TConnectionFactory.getInstance();
// Obtain the connection to the database
connection = connectionFactory.newConnection(URI);

//Get document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();

//Insert elements in the document
Element TAuthor = document.createElement(“Author”);
Element TAuthorName = document.createElement(“AuthorName”);
Element TLivingPeriod = document.createElement(“LivingPeriod”);
Element TTitles = document.createElement(“Titles”);

TAuthor.appendChild(TAuthorName);
TAuthor.appendChild(TLivingPeriod);
TAuthor.appendChild(TTitles);
document.appendChild(TAuthor);


//Get Accessor
TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor( TAccessLocation.newInstance( “ino:etc” ),TDOMObjectModel.getInstance());
TXMLObject xmlObject = TXMLObject.newInstance(TAuthor.toString());


TResponse response = null;
// Insert the XML document
// Invoke the insert operation and obtain the response
response = xmlObjectAccessor.insert( xmlObject );
// Show the collection, doctype and id
System.out.println( “Insert succeeded, ino:collection:” + xmlObject.getCollection() +
“, ino:doctype:” + xmlObject.getDoctype() +
“, ino:id:” + xmlObject.getId() );

}
catch(Exception e)
{
e.printStackTrace();
}
}

}

tnx a lot Vicky!
but maybe i’ve made a wrong question!

in your program you did:

 TXMLObject xmlObject = TXMLObject.newInstance(TAuthor.toString());
 </pre><BR><BR>you don't use StringReader but the method toString().<BR>What i wanted to know it's if is possibile to do:<BR><pre class="ip-ubbcode-code-pre"> TXMLObject xmlObject = TXMLObject.newInstance(DOMDOCUMENT);
 


without using a toString() method!

tnx again!

Hi Tobia,

It is possible to create TXMLObject instance as you are expecting.

ie. TXMLObject xmlObject = TXMLObject.newInstance(document);

Regards,

Vikram

Vikram Shinde
Software AG (India) Pvt. Ltd.

tnx a lot!
I’m going to try! :slight_smile: