Sónia Moreira

Integração Contínua & TFS & Scrum

My Links

Blog Stats

Archives

Post Categories

Blogs

Login

Obtain xml node text and attribute with XQuery

Imaginando que temos o seguinte documento xml em uma base de dados, guardado no campo Strategy que é do tipo xml:

<strategy cacheDuration="01:00:00">
  <pipeline type="RequestResponse">
    <tasks>
      <cache>
        <duration>00:05:00</duration>
      </cache>
      ...
    </tasks>
  </pipeline>
</strategy>

Se quisermos obter o valor do atributo cacheDuration e o texto do nó duration, fazemos a seguinte query:

SELECT
strategy.value('data((/strategy)[1]/@cacheDuration)','varchar(50)') as StrategyCache,
strategy.value('data((/strategy/pipeline/tasks/cache/duration/text())[1])','varchar(50)') as TaskCache
FROM strategy

Resultado:

StrategyCache          TaskCache
01:00:00                   00:05:00


Sónia Moreira

posted on Thursday, August 07, 2008 5:12 PM

Feedback

No comments posted yet
Title  
Name  
Url
Box Code
Protected by FormShield
Comments