Deletes nodes from an XML instance. 특정 노드 삭제

by kay posted Sep 24, 2015
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

xml 핸들링 시 필요 없는 노드 정리를 위한 방법.



DECLARE @myDoc xml
SET @myDoc = '<?Instructions for=TheWC.exe ?> 
<Root>
 <!-- instructions for the 1st work center -->
<Location LocationID="10" 
            LaborHours="1.1"
            MachineHours=".2" >Some text 1
<step>Manufacturing step 1 at this work center</step>
<step>Manufacturing step 2 at this work center</step>
</Location>
</Root>'
SELECT @myDoc

-- delete an attribute
SET @myDoc.modify('
  delete /Root/Location/@MachineHours
')
SELECT @myDoc

-- delete an element
SET @myDoc.modify('
  delete /Root/Location/step[2]
')
SELECT @myDoc

-- delete text node (in <Location>
SET @myDoc.modify('
  delete /Root/Location/text()
')
SELECT @myDoc

-- delete all processing instructions
SET @myDoc.modify('
  delete //processing-instruction()
')
SELECT @myDoc



참고 Url : https://msdn.microsoft.com/en-us/library/ms190254.aspx


Articles

1 2 3