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.

 View Only
  • 1.  how delete root element?!?

    Posted Thu May 20, 2004 02:28 AM

    Hello everyone,
    i need to delete an xml instance doc!
    My first idea it’s to do somethink like:

      public void doDelete(String AuthorName) {
    if(dataSource.chkConnection()) {
    dataSource=new DataSource();
    }
    String q="update delete input()/Author[AuthorName='"+AuthorName+"']";
    TXQuery query = TXQuery.newInstance(q);
    TXMLObjectAccessor xmlObjectAccessor = dataSource.getTXMLObjectAccessor();
    try {
    TResponse response = xmlObjectAccessor.xquery( query );
    }
    catch (TException insertException) {
    System.out.println( "Delete failed!" );
    System.out.println( insertException );
    }
    finally{
    dataSource.close();
    }
    }</pre><BR><BR>but i had:<BR><pre class="ip-ubbcode-code-pre">  NestedException:Tamino access failure (INOXQE6450, Update results in non-well-formed document, Attempt to delete the root element)



    I think maybe i need to use a dom object!
    I know how get a document from tamino but i don’t know how delete it!

    Thank you!


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


  • 2.  RE: how delete root element?!?

    Posted Thu May 20, 2004 04:36 AM

    I think the problem is that you are trying to delete the root element(Author), in which a update delete query may not work.

    try:
    1) getting the inoid of the Author/document you are trying to delete.

    2) Create an TXMLObject from :
    (e.g: String select = “for $a in input()/Author[AuthorName='”+AuthorName+“']”:wink:

    Doucment doc = …(from TResponse by parsing above query) …
    TXMLObject xmlobject = TXMLObject.newInstance(doc);
    xmlobject.setId(ino);

    3) Delete:
    accessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance(collection), TDOMObjectModel.getInstance());

    TResponse response = accessor.delete(xmlobject );

    this should work.


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


  • 3.  RE: how delete root element?!?

    Posted Thu May 20, 2004 12:38 PM

    tnx Bern!
    your help is gold for me! :slight_smile:
    i’ve found a different way…i use query instead of xquery:

      String q="/Author[AuthorName='"+AuthorName+"']";
    
    TQuery query = TQuery.newInstance(q);
    TXMLObjectAccessor xmlObjectAccessor = dataSource.getTXMLObjectAccessor();
    
    try {
    TResponse response = xmlObjectAccessor.delete( query );
    ...................



    your help had cleared to me some wrong ideas about Dom and xmlObject!
    so…
    do u think it’s better my way or your? and why?

    tnx again!


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


  • 4.  RE: how delete root element?!?

    Posted Fri May 21, 2004 12:40 AM

    Hello Tobia and Bern.

    It is also possible to delete a document via an XQuery update expression, but the key/tricky thing is to specify the document - not the root element.
    (Deleting the root element would leave an empty document hanging around, so you need to delete the document node.)

    Tobia, to modify the update delete expression in your first posting so that it deletes documents, just add “/…” to the end of it.
    At the moment it attempts to delete the root element, but the expression should select the parent of the root - the document…

    Please also see this posting for more information.

    I hope that helps,
    Trevor.


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


  • 5.  RE: how delete root element?!?

    Posted Fri May 21, 2004 02:41 PM

    Tnx Trevor!
    i’m sorry…i’ve made an “overloaded” topic! :slight_smile:
    So i try to add some ideas to this post! :slight_smile:
    Well…your solution -of course- works! :slight_smile:
    If i write:

     declare namespace tf='http://namespaces.softwareag.com/tamino/TaminoFunction' 
    update for $i in input()/Author[AuthorName='xxxxx'] 
    do delete $i/.. 



    taking away the “where” expression i expected an error like “attempt to delete the root element” or “ino:id required” or something like this!
    But it seems to work well! I think depends from the “$i/…” expression that returns the document itself (as you wrote in the other topic)!
    My question is…is this query correct? or it works becouse i’ve few instance in my db?


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


  • 6.  RE: how delete root element?!?

    Posted Fri May 21, 2004 08:02 PM

    Hi Tobia!

    Your query (as presented in the previous posting) is correct. The example “delete query” that I posted in the other thread was based upon Michelle’s original query, that is the only reason that the ino:id attribute was used.

    In your case, the root element “Author” is selected (where AuthorName=‘xxxxx’), and then the parent of “Author” is deleted. The parent of author is the document, so the effect is that the document is deleted.

    You could also drop the filter condition / where clause - [AuthorName=‘xxxxx’] - to delete all the Author documents, and this will remain a valid / working expression.
    If you get into a large number of documents, it is conceivable that attempting to delete all of them will take longer than the “maximum query duration” (or maximum transaction) setting on the database…

    One last thing: you don’t need to declare the “tf” namespace in your query - that was only required for the tf:getInoId() function.

    Cheers,
    Trevor.


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


  • 7.  RE: how delete root element?!?

    Posted Mon May 24, 2004 11:26 AM

    Tnx a lot for your explanation Trevor,
    i’ll follow your advice!


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