Solved

Create Xml string and update table column using stored proc

Posted on 2008-10-30
2
722 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

729 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