久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

根據同級值查詢 XML 數據以獲取信息

Query XML data for information based on a sibling value(根據同級值查詢 XML 數據以獲取信息)
本文介紹了根據同級值查詢 XML 數據以獲取信息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有以下 XML 數據,我對其進行零控制.請注意,它基本上是屬性組的集合.我需要選擇一個屬性的值,其中另一個屬性的值為true".問題是,沒有什么可分組的,我不知道如何正確關聯.

I have the following XML data, which I have zero control over. Note that it's basically a collection of property groups. I need to select the value of one property where the value of another property is 'true'. The problem is, there's nothing to group on, and I cannot figure out how to associate things correctly.

這是 XML 數據,以及我目前想到的查詢:

Here's the XML Data, and the query I came up with so far:

DECLARE @xml xml = '
<Container>
  <Collection>
    <ItemName>SomeItem</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>false</IsPersisted>
  </Collection>
  <Collection>
    <ItemName>AnotherItem</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>true</IsPersisted>
    <ExistsInDB>true</ExistsInDB>
  </Collection>
  <Collection>
    <ItemName>ItemFoo</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>true</IsPersisted>
    <ExistsInDB>true</ExistsInDB>
  </Collection>
  <Collection>
    <ItemName>BarBazItem</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>true</IsPersisted>
    <ExistsInDB>false</ExistsInDB>
  </Collection>
</Container>
'

;WITH XmlStuff AS (
    SELECT CAST(xmlShredded.colXmlItem.query('local-name(.)') AS nvarchar(4000)) as XmlNodeName,
        xmlShredded.colXmlItem.value('.', 'nvarchar(4000)') AS XmlNodeValue
    FROM @xml.nodes('/*/Collection/child::node()') as xmlShredded(colXmlItem) 
)
SELECT *
FROM XmlStuff 

現在,我需要做的是為ExistsInDB"為true"的每個分組獲取ItemName"值.請注意,第一個屬性集合中不存在ExistsInDB"屬性(即,應將其視為 NULL/false).

Now, what I need to do, is get the "ItemName" value for each grouping where "ExistsInDB" is 'true'. Note that the "ExistsInDB" property doesn't exist in the first property collection (i.e. it should be considered NULL/false).

所以在這種情況下,我需要查詢這個xml數據,并取回以下集合:

So in this case, I need to query this xml data, and get back the following set:

另一個項目ItemFoo

AnotherItem ItemFoo

我不應該得到SomeItem"或BarBazItem".

I should NOT get "SomeItem" or "BarBazItem".

我一直在努力弄清楚如何制定獲取所有 ItemName 值,其中關聯的 ExistsInDB 值都存在且為真"的查詢.

I've been beating my head against the desk trying to figure out how to formulate the query for "Get all ItemName values where the associated ExistsInDB value is both present, and true".

這甚至可能嗎?

推薦答案

也許試試兄弟匹配

/Container/Collection/ItemName[../ExistsInDB='true']

獲取 ItemName 元素,其父元素包含等于true"的 ExistsInDb 子元素.

That gets ItemName elements whose parents contain an ExistsInDb child equal to "true".

DECLARE @xml xml = '
<Container>
  <Collection>
    <ItemName>SomeItem</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>false</IsPersisted>
  </Collection>
  <Collection>
    <ItemName>AnotherItem</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>true</IsPersisted>
    <ExistsInDB>true</ExistsInDB>
  </Collection>
  <Collection>
    <ItemName>ItemFoo</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>true</IsPersisted>
    <ExistsInDB>true</ExistsInDB>
  </Collection>
  <Collection>
    <ItemName>BarBazItem</ItemName>
    <IsDeletable>true</IsDeletable>
    <IsPersisted>true</IsPersisted>
    <ExistsInDB>false</ExistsInDB>
  </Collection>
</Container>
';

SELECT node.value('.', 'nvarchar(100)')
FROM @xml.nodes('/Container/Collection/ItemName[../ExistsInDB="true"]') AS x(node) 

這篇關于根據同級值查詢 XML 數據以獲取信息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 亚洲第一成年免费网站 | 亚洲电影一区二区三区 | 日本精品久久久一区二区三区 | 男女激情网 | 91热在线| 色综合久久久久 | 欧美freesex黑人又粗又大 | 中日av | 日本不卡视频在线播放 | 中文字幕久久久 | 亚洲国产欧美在线人成 | 99热这里都是精品 | a级片网站| 四虎最新视频 | 欧美精品日韩精品 | 精品亚洲永久免费精品 | 免费观看www7722午夜电影 | 亚洲一区国产 | 做a的各种视频 | 黄网免费 | 91亚洲精选 | 视频一区二区在线 | 日本理论片好看理论片 | 毛片免费观看 | 久久国产一区二区三区 | 久久亚洲精品视频 | 久草院线| 亚洲人人 | 亚洲第一成人av | 日本免费视频 | 色婷婷一区二区三区四区 | 国产91在线播放 | 九九久久精品视频 | 免费视频成人国产精品网站 | 久久久久久国产精品三区 | 在线色网| 日本久久www成人免 成人久久久久 | 啪啪免费网 | 日韩一及片 | 亚洲伊人久久综合 | 久久久久久九九九九 |