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

发布于 2024-08-21 01:10:58 字数 692 浏览 4 评论 0原文

我有一些数据,如底部所示。我使用 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>

I have some data like at the bottom. I use SQL Server 2000 stored proc to process this data using sp_xml_preparedocument .

I would like to get the data within the node PartAuxiliaryID as it is below(the exact xml as it is, not the values or attribute) to a variable. What will be the best way to do that in stored proc using 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2024-08-28 01:10:58

我找到了答案

选项 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>\

I found the answer

Option 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>

Option 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

will get the following as two rows

   <Info name="quoteNumber">962445</Info>
   <Info name="shipSourceType">INTERNAL</Info>\
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文