Problem adding elements to an XML document in Tamino

Tamino Version: 3.1.1.1
Using Xalan and DOM

Here is my XML:



11
22


33
44




I would like to add a new NEWS story with ID=3 after the second one. After adding the new news story the XML document will be as follows.




11
22


33
44


55
66




I am using DOM to work with the XML.
Here is my Java code…

TaminoClient tamino = new TaminoClient(myURL + “/” + myCollection);
tamino.setPageSize(myPageSize);
tamino.setSAXimplementer(“com.jclark.xml.sax.Driver”);
tamino.startSession();
TaminoResult tr = tamino.query("/TEST");

while (tr.hasMoreElements())
{
Element myElement = tr.getNextElement();
NodeList myNodeList = myElement.getElementsByTagName(“LATEST”);
Node myNode = myNodeList.item(0);
Node newNode = myNodeList.item(0);
Node myParent = myNode.getParentNode();

newNode = (tr.getDocument()).createElement( “LATEST” );
//This is where I am not sure what to do to insert a new news article.

myParent.appendChild( newNode );
TaminoResult lasttr = tamino.update(myElement);
tamino.commit(false);
}


Any help would be much appreciated.

Thank You :slight_smile:

I have solved my problem.
Here is the code.

while (tr.hasMoreElements())
{
Element myElement = tr.getNextElement();
NodeList myNodeList = myElement.getElementsByTagName(“LATEST”);
Node myNode = myNodeList.item(0);
Node newNode = myNodeList.item(0);
Node myParent = myNode.getParentNode();

BasicDocument doc = new BasicDocument();
BasicElement newsStory = new BasicElement(doc,“LATEST”);
newsStory.setAttribute(“DISPLAY”, display);

BasicElement c = new BasicElement(doc,“TITLE”);
c.appendChild(new BasicText(doc,title));
newsStory.appendChild(c);

c = new BasicElement(doc,“BODY”);
c.appendChild(new BasicText(doc,body));
newsStory.appendChild(c);
myParent.appendChild( newsStory );

TaminoResult lasttr = tamino.update(myElement);
tamino.commit(false);
}
tamino.endSession();