SQL Server 2000 sp_xml_preparedocument - 获取节点的innerxml / innertext

时间:2010-02-12 13:52:51

标签: sql-server xml sql-server-2000

我有一些像底部的数据。我使用SQL Server 2000存储过程来使用sp_xml_preparedocument处理此数据。

我想获取节点PartAuxiliaryID中的数据,因为它在下面(确切的xml,不是值或属性)到变量。使用sp_xml_preparedocument

在存储过程中执行此操作的最佳方法是什么
     <Info name="quoteNumber">962445</Info> 
     <Info name="shipSourceType">INTERNAL</Info> 

  <Data> 
  <Item>
   <ItemID>
       <PartID>1234</PartID>
        <PartAuxiliaryID>
          <Info name="quoteNumber">962445</Info> 
           <Info name="shipSourceType">INTERNAL</Info> 
        </PartAuxiliaryID>
   </ItemID>
  </Item></Data>

1 个答案:

答案 0 :(得分:1)

我找到了答案

选项1

DECLARE @xmlData varchar(3000)
SET  @xmlData = '<Data> 
      <Item>
       <ItemID>
           <PartID>1234</PartID>
            <PartAuxiliaryID>
              <Info name="quoteNumber">962445</Info> 
               <Info name="shipSourceType">INTERNAL</Info> 
            </PartAuxiliaryID>
       </ItemID>
      </Item></Data>'

DECLARE @idoc int, @intRet int
DECLARE @URL VARCHAR(1000)
EXEC @intRet= sp_xml_preparedocument @idoc OUTPUT, @xmlData

SELECT *
FROM OPENXML (@idoc, '/Data/Item/ItemID/PartAuxiliaryID')
WITH (PartAuxiliaryID varchar(2000) '@mp:xmltext')

EXEC sp_xml_removedocument @idoc
-------------------------------------------------------------------------------
--will get the following 

    <PartAuxiliaryID><Info name="quoteNumber">962445</Info><Info name="shipSourceType">INTERNAL</Info></PartAuxiliaryID>

选项2

DECLARE @xmlData varchar(3000)
SET  @xmlData = '<Data> 
      <Item>
       <ItemID>
           <PartID>1234</PartID>
            <PartAuxiliaryID>
              <Info name="quoteNumber">962445</Info> 
               <Info name="shipSourceType">INTERNAL</Info> 
            </PartAuxiliaryID>
       </ItemID>
      </Item></Data>'

DECLARE @idoc int, @intRet int
DECLARE @URL VARCHAR(1000)
EXEC @intRet= sp_xml_preparedocument @idoc OUTPUT, @xmlData

SELECT *
FROM OPENXML (@idoc, '/Data/Item/ItemID/PartAuxiliaryID/Info')
WITH (PartAuxiliaryID varchar(2000) '@mp:xmltext')

EXEC sp_xml_removedocument @idoc

将获得以下两行

   <Info name="quoteNumber">962445</Info>
   <Info name="shipSourceType">INTERNAL</Info>\