User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the RSS, Web Services and SOAP section within the Web Development category of DaniWeb, a massive community of 402,059 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,398 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our RSS, Web Services and SOAP advertiser: Programming Forums
Views: 3946 | Replies: 16
Reply
Join Date: Oct 2007
Posts: 31
Reputation: ssahil11 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ssahil11 ssahil11 is offline Offline
Light Poster

XML Update??

  #1  
Dec 13th, 2007
What is the query to update an element in XML document?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 76
Reputation: dilasing is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dilasing dilasing is offline Offline
Junior Poster in Training

Re: XML Update??

  #2  
Dec 18th, 2007
DB2 9 does not support updating an element in XML documents, you must perform a full-document update using the UPDATE SQL statement.


UPDATE customer SET info =
'<customerinfo xmlns="http://posample.org" Cid="1002">
<name>Jim Noodle</name>
<addr country="Canada">
<street>1150 Maple Drive</street>
<city>Newtown</city>
<prov-state>Ontario</prov-state>
<pcode-zip>Z9Z 2P2</pcode-zip>
</addr>
<phone type="work">905-555-7258</phone>
</customerinfo>'
WHERE XMLEXISTS (
'declare default element namespace "http://posample.org";
$doc/customerinfo[@Cid = 1002]'
passing INFO as "doc")

The XMLEXISTS predicate ensures that only the document containing the attribute Cid="1002" is replaced. Notice how the predicate expression in XMLEXISTS, [@Cid = 1002], is not specified as a string comparison: [@Cid = "1002"]. This is because the index, previously created, for the Cid attribute was defined with the DOUBLE data type. In order for the index to match this query, Cid cannot be specified as a string in the predicate expression.

MTK can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at
http://www-1.ibm.com/support/docview...id=swg27009230.
Reply With Quote  
Join Date: Oct 2007
Posts: 31
Reputation: ssahil11 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ssahil11 ssahil11 is offline Offline
Light Poster

Re: XML Update??

  #3  
Dec 26th, 2007
I am working on DB2 9; I want to update XML sub-document. Is there any way to update a particular element value?
Reply With Quote  
Join Date: Oct 2007
Posts: 76
Reputation: dilasing is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dilasing dilasing is offline Offline
Junior Poster in Training

Re: XML Update??

  #4  
Dec 27th, 2007
XML documents are stored natively in DB2 and there is no out-of-the-box functionality for performing sub-document updates.

One solution to this problem is to bring the document over the client, modify it, and then save it back into the database. This approach is limited by the XML capabilities of the client environment.

There is another solution. By creating an update stored procedure it is possible to update XML documents in the database without having to bring them over the client. This stored procedure enables partial updates of XML documents.

For example, DB2XMLFUNCTIONS.XMLUPDATE is a java-based stored procedure. The following example updates XML document by replacing the simple name element with a complex name element.

Call DB2XMLFUNCTIONS.XMLUPDATE (
'<updates namespaces="x:http://posample.org">
<update action="replace" col="1" path="/x:customerinfo/x:name">
<name><fname>Hardeep</fname><lname>Singh</lname></name>
</update>
</updates>',
'Select info from CUSTOMER where cid=1006',
'update CUSTOMER set info=? where cid=1006',?,?);

You can download jar file and examples at:
http://www.ibm.com/developerworks/db.../dm-0605singh/
Reply With Quote  
Join Date: Oct 2007
Posts: 31
Reputation: ssahil11 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ssahil11 ssahil11 is offline Offline
Light Poster

Re: XML Update??

  #5  
Dec 28th, 2007
How to setup and register the db2xmlfunctions.XMLUPDATE java based update store procedure in DB2 9?
Reply With Quote  
Join Date: Oct 2007
Posts: 76
Reputation: dilasing is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dilasing dilasing is offline Offline
Junior Poster in Training

Re: XML Update??

  #6  
Jan 2nd, 2008
Steps to setup the update stored procedure:

i) Download db2xmlfunctions.jar file and source code from http://www.ibm.com/developerworks/vi...cale=worldwide

ii) On Microsoft Windows, open a DB2 command window:


SET CLASSPATH= .;%DB2PATH%\java\db2java.zip;
%DB2PATH%\java\db2jcc.jar;
%DB2PATH%\java\db2jcc_license_cisuz.jar;
"%DB2PATH%\java\jdk\bin\javac.exe" -d . *.java
"%DB2PATH%\java\jdk\bin\jar" cvf db2xmlfunctions.jar com/ibm/db2/xml/functions/*.class


iii) Install the stored procedure in DB2
DB2 -t
connect to your_dbname;
CALL SQLJ.INSTALL_JAR('file:/temp/samples/db2xmlfunctions.jar' ,
db2xmlfunctions,0);
iv) Register the stored procedure in your database:

CREATE PROCEDURE db2xmlfunctions.XMLUPDATE(
IN COMMANDSQL VARCHAR(32000),
IN QUERYSQL VARCHAR(32000),
IN UPDATESQL VARCHAR(32000),
OUT errorCode INTEGER, OUT errorMsg VARCHAR(32000))
DYNAMIC RESULT SETS 0
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO DBINFO
FENCED
NULL CALL MODIFIES SQL DATA
PROGRAM TYPE SUB
EXTERNAL NAME b2xmlfunctions:com.ibm.db2.xml.functions.XMLUpdate.Update';
TERMINATE;


You can read more at:
http://www.ibm.com/developerworks/db.../dm-0605singh/
Reply With Quote  
Join Date: Oct 2007
Posts: 31
Reputation: ssahil11 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ssahil11 ssahil11 is offline Offline
Light Poster

Re: XML Update??

  #7  
Jan 3rd, 2008
What are the uses of db2xmlfunctions.jar java based xml update stored procedure? Does anyone have idea about XMLUPDATE function, especially the syntax?
Reply With Quote  
Join Date: Oct 2007
Posts: 76
Reputation: dilasing is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dilasing dilasing is offline Offline
Junior Poster in Training

Re: XML Update??

  #8  
Jan 4th, 2008
The java based xml update stored procedure can be used for:

i) Changing the value of any text or attribute nodes in the target XML document.
ii) Replacing an element node in the XML document with another XML element along with all it child nodes.
iii) Deleing a node in the XML document.
iv) Inserting a new element.
v) Multiple updates to the source documents.
vi) Updates to multiple source documents.
vii) Replacing another XML document with the modified one.
viii) Inserting the modified document into a new record.

The update information can be:

i) Statically embedded in the update call
ii) Dynamically created at runtime using SQL.
iii) Computed using an arithmetic expression on the original text or attribute value.

The syntax of XMLUPDTE function is:

DB2XMLFUNCTIONS.XMLUPDATE (commandXML, querySQL, updateSQL, errorCode, errorMsg)

· commandXML à this argument is an XML string that encapsulates the update commands. These commands are then applied to the XML documents selected by the querySQL.
The structure of this command is:
<updates namespaces="">
<update using="" col="" action="" path="">update value</update>
</updates>
· querySQL à any valid SQL select statement that retrieves the XML documents that need to be update.
· updateXQL à It represents a parameterized update SQL. The modified XML document is bound to the update SQL as a runtime parameter. It allows a modified XML document to be saved to other XML columns in the database.
· errorCode à a value of -1 indicates that the stored procedure was aborted due to some error. If the update was successful, a positive value indicating the number of records that have been updated is returned.
· errorMsg à error message, including any exception thrown by the XML parse and the JCC driver.

You can find more information at:
http://www.ibm.com/developerworks/db.../dm-0605singh/
Reply With Quote  
Join Date: Oct 2007
Posts: 31
Reputation: ssahil11 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ssahil11 ssahil11 is offline Offline
Light Poster

Re: XML Update??

  #9  
Jan 8th, 2008
I made some changes to db2 xml update stored procedure. I want to remove this. How do I remove the store procedure in DB2?
Reply With Quote  
Join Date: Oct 2007
Posts: 76
Reputation: dilasing is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dilasing dilasing is offline Offline
Junior Poster in Training

Re: XML Update??

  #10  
Jan 17th, 2008
If you make any changes to the stored procedure, you should first drop the store procedure from DB2 and then call remove stored procedure jar statement. You can use below steps to remove stored procedure.

//dropping db2 xml update stored procedure.
DROP PROCEDURE DB2XMLFUNCTIONS.XMLUPDATE(VARCHAR(32000),
VARCHAR(32000),VARCHAR(32000),INTEGER, VARCHAR(32000));

//removing xml update java based stored procedure jar.
CALL SQLJ.REMOVE_JAR(DB2XMLFUNCTIONS);
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb RSS, Web Services and SOAP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the RSS, Web Services and SOAP Forum

All times are GMT -4. The time now is 12:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC