Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create Xml string and update table column using stored proc

Posted on 2008-10-30
2
Medium Priority
?
738 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

972 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