Solved

Create Xml string and update table column using stored proc

Posted on 2008-10-30
2
692 Views
Last Modified: 2013-11-18
I have the following string stored in my database column called TreeXml.


<C filename="00013024228c4e24a79bae959588acd4" parents="9daf7c70ac37479b8f91ef7bd08e07e6" DateModified="1217355187" taxonomyId="6aa742c4edff43a798c9067a2a4e223c" typeId="514044723" typeName="Answer" title="No" description=""><Conclusion /><Ps><P name="Approved" value="true" /><P name="Global or Country" value="Global" /><P name="Display on Questionaire" value="EA" /><P name="SL/SSL Owner /Maintained" value="02" /><P name="Sort Key" value="125" /><P name="Unique Number" value="963478" /></Ps></C>


I need to update this string
to add a new attribute called "Modified" in the  <C ...so the new string sould be

<C filename="00013024228c4e24a79bae959588acd4" parents="9daf7c70ac37479b8f91ef7bd08e07e6" DateModified="1217355187" taxonomyId="6aa742c4edff43a798c9067a2a4e223c" typeId="514044723" typeName="Answer" title="No" description=""  Modified="xyz ">


i am getting this xyz value using this

Select top (1)  C.UserName as LastModifiedBy
      from      QMSDocuments D
                  join QMSTaxonomyNames T on D.TaxonomyID = T.TaxonomyID
                  join QMSChanges C on C.Rowid = D.Rowid
      where      DocumentID = '00013024228c4e24a79bae959588acd4' order by C.ChangeDate desc



How do i achieve all this  in a stored proc
0
Comment
Question by:angireddy
2 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 500 total points
ID: 22893903
Well the way to do this properly is to create an XML DOM and using the LoadXML() method to load the string you have read from the database into it.

You now need to select the "C" node like

    cNode = xmldom.selectSingleNode('/C');

and then create a new attribute node with

   attrNode = xmldom.CreateAttribute('Modified');

and then set it's value :-

    attrNode.Value = today();  // or whatever

now add the new attribute to the attribute of the C node

    cNode.attributes.setNamedItem(attrNode);

and then save the document into a string

    str = xmldom.xml

and then write the string back into the database.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now