XML : TSQL xml.modify replace value for node with value

I need to update a xml node in a TSQL column.

I see many examples of using an xpath and identifying the node using the attribute.

The XML I am working with is auto generated and does not come with attributes on the nodes I need. How would I construct the update statement to use another value in the node to find it?

I'm hoping to be able to write something like this:

  declare @xml xml ='  <Content>  <ContentItems>      <ContentItem>          <ContentKey>abc</ContentKey>          <Body>TextToUpdate</Body>      </ContentItem>      <ContentItem>          <ContentKey>efg</ContentKey>          <Body>Other</Body>      </ContentItem>  </ContentItems>  </Content>'    select @xml    set @xml.modify(  '  replace value of   (/content/contentitems[ContentKey="abc"]/body/text())[1]    with ("Success")')    select @xml    

No comments:

Post a Comment