AppendChild Method

I am attemping to use AppendChild to add another iteration of an element instead of appending data to an existing element.
So if I have

In Java I want to Append another payment.

9876
ccccc>
pppp
bbbb

So conceptionally it will result in this:


9876
ccccc>
pppp
sssss
bbbb


This is my Java Code:
String data = rec1;
TLocalTransaction localTransaction = tcon.useLocalTransactionMode();

// In update

TXMLObject objAuthor = ti.next();

Element elemAuthor = (Element) objAuthor.getElement();

Document doc = elemAuthor.getOwnerDocument();

Element elemTitle = doc.createElement(fieldName);
Text textTitle = doc.createTextNode(data);

elemTitle.appendChild( textTitle);
elemAuthor.appendChild(elemTitle);
tacc.update(objAuthor);
// End of Update
System.out.println(" Update in completed");


localTransaction.commit();

When I run this I get :

Nested Exception ( com.softwareag.tamino.db.API.common.TAccessFailureException, tag: JavaTaminoAPI_4_1_4_42_1_1, java: 1.3.1, os: Windows XP 5.1 ) stacktrace:

Tamino access failure (INOXDE7731, (cvc-model-group.1):invalid sequence, Line 1, Column 1086: Line 1, Column 1086: [element “Paydtl_line” in element “Tax”])
at com.softwareag.tamino.db.API.accessor.TAccessFailureVerifier.newAccessFailureException(Unknown Source)
at com.softwareag.tamino.db.API.accessor.TAccessFailureVerifier.verify(Unknown Source)
at com.softwareag.tamino.db.API.accessor.TAccessFailureVerifier.verifyUpdateResponse(Unknown Source)
at com.softwareag.tamino.db.API.accessor.TXMLObjectAccessorImpl.update(Unknown Source)
at com.softwareag.tamino.db.API.examples.greeting.AppendChild.main(AppendChild.java:161)
Exception in thread “main”


HELP…

Hi,
This is really a problem with your DOM structure after the appendChild. If you start with this structure:

<Tax>
<taxkey>9876</taxkey>
<Coll_line>ccccc</Coll_line>
<Paydtl_line>pppp</Paydtl_line>
<Bond_line>bbbb</Bond_line>
</Tax></pre> and then you appendChild() a new Paydtl_line element to the Tax root element, you get <pre class="ip-ubbcode-code-pre"><Tax>
<taxkey>9876</taxkey>
<Coll_line>ccccc</Coll_line>
<Paydtl_line>pppp</Paydtl_line>
<Bond_line>bbbb</Bond_line>
<Paydtl_line>qqqq</Paydtl_line>
</Tax></pre>This is not valid against the schema (you have a Paydtl_line element after a Bond_line element) so Tamino's error message is correct. What you are aiming at is:<pre class="ip-ubbcode-code-pre"><Tax>
<taxkey>9876</taxkey>
<Coll_line>ccccc</Coll_line>
<Paydtl_line>pppp</Paydtl_line>
<Paydtl_line>qqqq</Paydtl_line>
<Bond_line>bbbb</Bond_line>
</Tax>


The solution depends, to an extent, on what DOM model you are using. Is this enough?
HTH

I am reatively new at this, so I am looking for advice on how to accomplish this.
Which DOM model should I be using?
An example would be even better.

Assuming you are using DOM (as opposed to JDOM, and the choice is entirely up to you), here is an example of how you might add your new Element:

TXMLObject xmlObject = response.getFirstXMLObject();
      // Get top-level Tax element
      Element root = (Element) xmlObject.getElement();
      
      //Build the new child Element and give it Text content 
      Document doc = root.getOwnerDocument();
      Element newDetail = doc.createElement("Paydtl_line");
      Text textValue = doc.createTextNode("qqqq");
      newDetail.appendChild( textValue);

      // Manipulate the DOM to add our new child in the correct place
      // Principle - get the last "Pay_dtl" node;
      //             get the following "Bond_line" if there is one (optional Node in Schema)
      //             insertBefore() the Bond_line or appendChild() if there are no Bond_lines.
      NodeList payDetails = root.getElementsByTagName("Paydtl_line");
      Node lastDetail = payDetails.item(payDetails.getLength()-1);  
      Node firstBond = lastDetail.getNextSibling();
      if (firstBond != null) 
        root.insertBefore(newDetail,firstBond);
      else
        root.appendChild(newDetail);
      // Update the existing Tax instance in Tamino
      response = accessor.update(xmlObject);
      System.out.println("Response to update: " + response.getReturnValue());


It’s not pretty and there are probably other ways to achieve this, but it should get you started.