IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#TechXchangePresenter
 View Only
Expand all | Collapse all

Problem adding elements to an XML document in Tamino

  • 1.  Problem adding elements to an XML document in Tamino

    Posted Wed December 17, 2003 04:03 PM

    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:


    #API-Management
    #webMethods-Tamino-XML-Server-APIs
    #webMethods


  • 2.  RE: Problem adding elements to an XML document in Tamino

    Posted Wed December 17, 2003 05:54 PM

    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();


    #webMethods-Tamino-XML-Server-APIs
    #webMethods
    #API-Management