1

我在表中有以下 xml

<GetOrdersResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <Timestamp>2013-09-07T06:38:46.192Z</Timestamp>
  <Ack>Success</Ack>
  <Version>837</Version>
  <Build>E837_CORE_APIXO_16317239_R1</Build>
  <HasMoreOrders>true</HasMoreOrders>
  <OrdersPerPage>100</OrdersPerPage>
  <PageNumber>1</PageNumber>
  <ReturnedOrderCountActual>48</ReturnedOrderCountActual>
  <PaginationResult>
    <TotalNumberOfPages>9</TotalNumberOfPages>
    <TotalNumberOfEntries>881</TotalNumberOfEntries>
  </PaginationResult>
  <OrderArray>
    <Order>
      <OrderID>1</OrderID>
    </Order>
    <Order>
      <OrderID>2</OrderID>
    </Order>
  </OrderArray>
</GetOrdersResponse>

我已经写了下面的查询并得到 2 行 balank(not null) 结果

select xmlresponse.value('(/GetOrdersResponse/OrderArray)[1]','varchar(max)')
from ordersxml

我想得到如下结果

Row1:   <Order>
          <OrderID>1</OrderID>
        </Order>

Row2:   <Order>
           <OrderID>2</OrderID>
        </Order>
4

1 回答 1

1

忽略了 XML 文档中定义的 XML 命名空间!

<GetOrdersResponse xmlns="urn:ebay:apis:eBLBaseComponents">
                   ***************************************

您需要在查询中使用它 - 如下所示:

;WITH XMLNAMESPACES(DEFAULT 'urn:ebay:apis:eBLBaseComponents')
    SELECT
        XOrder.query('.')
    FROM 
        dbo.YourTableInQuestionHere
    CROSS APPLY 
        XMLDATA.nodes('/GetOrdersResponse/OrderArray/Order') AS XTbl(XOrder)

这会将两个<Order>节点及其内容返回给您。

于 2013-09-08T06:49:09.570 回答