1. <legend id='klCDC'><style id='klCDC'><dir id='klCDC'><q id='klCDC'></q></dir></style></legend>
        <bdo id='klCDC'></bdo><ul id='klCDC'></ul>

      <i id='klCDC'><tr id='klCDC'><dt id='klCDC'><q id='klCDC'><span id='klCDC'><b id='klCDC'><form id='klCDC'><ins id='klCDC'></ins><ul id='klCDC'></ul><sub id='klCDC'></sub></form><legend id='klCDC'></legend><bdo id='klCDC'><pre id='klCDC'><center id='klCDC'></center></pre></bdo></b><th id='klCDC'></th></span></q></dt></tr></i><div id='klCDC'><tfoot id='klCDC'></tfoot><dl id='klCDC'><fieldset id='klCDC'></fieldset></dl></div>
    2. <small id='klCDC'></small><noframes id='klCDC'>

    3. <tfoot id='klCDC'></tfoot>

        从父节点 xml sql server 检索所有子节点

        时间:2023-06-07
          <bdo id='t3Qrs'></bdo><ul id='t3Qrs'></ul>

            1. <i id='t3Qrs'><tr id='t3Qrs'><dt id='t3Qrs'><q id='t3Qrs'><span id='t3Qrs'><b id='t3Qrs'><form id='t3Qrs'><ins id='t3Qrs'></ins><ul id='t3Qrs'></ul><sub id='t3Qrs'></sub></form><legend id='t3Qrs'></legend><bdo id='t3Qrs'><pre id='t3Qrs'><center id='t3Qrs'></center></pre></bdo></b><th id='t3Qrs'></th></span></q></dt></tr></i><div id='t3Qrs'><tfoot id='t3Qrs'></tfoot><dl id='t3Qrs'><fieldset id='t3Qrs'></fieldset></dl></div>
              <legend id='t3Qrs'><style id='t3Qrs'><dir id='t3Qrs'><q id='t3Qrs'></q></dir></style></legend>

              1. <tfoot id='t3Qrs'></tfoot>

                <small id='t3Qrs'></small><noframes id='t3Qrs'>

                    <tbody id='t3Qrs'></tbody>

                  本文介绍了从父节点 xml sql server 检索所有子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有这个 xml:

                  <viewNode xsi:type="View:Projection" name="Projection_1">
                  <endUserTexts label=" "/>
                  <element name="CITY">
                    <inlineType primitiveType="CHAR" length="0" precision="0" scale="0"/>
                  </element>
                  <element name="ROAD_ID">
                    <inlineType primitiveType="CHAR" length="0" precision="0" scale="0"/>
                  </element>
                  <element name="LEN">
                    <inlineType primitiveType="CHAR" length="0" precision="0" scale="0"/>
                  </element>
                  <element name="CITY2">
                    <inlineType primitiveType="CHAR" length="0" precision="0" scale="0"/>
                  </element>
                  <element name="F">
                    <inlineType name="INTEGER" primitiveType="INTEGER" length="0" precision="0" scale="0"/>
                  </element>
                  <elementFilter elementName="F">
                    <valueFilter xsi:type="Column:SingleValueFilter" including="true" value="1"/>
                  </elementFilter>
                  <input>
                    <viewNode xsi:type="View:JoinNode">#/0/Join_1</viewNode>
                    <mapping xsi:type="Type:ElementMapping" targetName="CITY" sourceName="CITY"/>
                    <mapping xsi:type="Type:ElementMapping" targetName="ROAD_ID" sourceName="ROAD_ID"/>
                    <mapping xsi:type="Type:ElementMapping" targetName="LEN" sourceName="LEN"/>
                    <mapping xsi:type="Type:ElementMapping" targetName="CITY2" sourceName="CITY2"/>
                    <mapping xsi:type="Type:ElementMapping" targetName="F" sourceName="F"/>
                  </input></viewNode>
                  

                  这是我检索数据的代码:

                  and this is my code to retrieve the data:

                  SELECT 
                  Tab.Col.value('../@name','nvarchar(50)') as ViewNode,
                  Tab.Col.value('@name','nvarchar(50)') as Name,
                  Tab.Col.value('(endUserTexts/@label)[1]','nvarchar(50)') as Label,  
                  Tab.Col.value('(inlineType/@primitiveType)[1]','nvarchar(50)') as PrimitveType, 
                  Tab.Col.value('(inlineType/@length)[1]','nvarchar(50)') as Length,  
                  Tab.Col.value('(inlineType/@precision)[1]','nvarchar(50)') as Precision,    
                  Tab.Col.value('(inlineType/@scale)[1]','nvarchar(50)') as Scale 
                  FROM @x.nodes('/viewNode/element') AS Tab(Col)
                  

                  这种方式有效并检索每个元素的数据,但我还想从 elementFilter 检索数据,并将其视为另一个元素.我的问题是,有没有办法检索父节点 viewNode 的所有子节点?

                  This way works and retrieves the data for each element, but I would like to also retrieve the data from elementFilter, and treat it as if it were another element. My question is, there is a way to retrieve all the child nodes of the parent node viewNode?

                  类似于FROM @x.nodes('/viewNode/ANYCHILDNODE') AS Tab(Col)

                  推荐答案

                  首先:提供的示例不完整,因为缺少命名空间 xsi 的声明.在我的示例中,我添加了一个虚拟声明...

                  First of all: The provided example cannot be complete as there is a declaration for the namespace xsi missing. In my example I've added a dummy declaration...

                  这种方式有效并检索每个元素的数据,但我会还喜欢从 elementFilter 中检索数据,并将其视为如果它是另一个元素.我的问题是,有一种方法可以检索父节点viewNode的所有子节点?就像是FROM @x.nodes('/viewNode/ANYCHILDNODE') AS Tab(Col)

                  This way works and retrieves the data for each element, but I would like to also retrieve the data from elementFilter, and treat it as if it were another element. My question is, there is a way to retrieve all the child nodes of the parent node viewNode? Something like FROM @x.nodes('/viewNode/ANYCHILDNODE') AS Tab(Col)

                  在这种情况下,最好提供预期的输出...

                  In such cases it was best to provide the expected output...

                  不共享相同的属性.而 完全是另一回事,包括与 1:n 相关的 数组本身...

                  <element> and <elementFilter> do not share the same attributes. And <input> is something else entirely, including a 1:n related <mapping> array itself...

                  所以:是的,有 * 的意思是 ANYCHILD.像 /viewNode/* 这样的 XPath 将返回 下的所有子节点.然后,您可以使用 local-name() 对元素的名称做出正常的反应.在下面的代码中,我向 XPath 添加了一个 substring predicate 以返回以短语 element 开头的元素.这将返回 但将忽略 .试试看:

                  So: Yes, there is * meaning ANYCHILD. An XPath like /viewNode/* will return all children below <viewNode>. You can then use local-name() to react on an element's name gerically. In the following clode I add a substring predicate to the XPath in order to return elements starting with the phrase element. This will return <element> and <elementFilter> but will ignore <input>. Try it out:

                  DECLARE @x XML=
                  N'<viewNode xmlns:xsi="dummy" xsi:type="View:Projection" name="Projection_1">
                    <endUserTexts label=" " />
                    <element name="CITY">
                      <inlineType primitiveType="CHAR" length="0" precision="0" scale="0" />
                    </element>
                    <element name="ROAD_ID">
                      <inlineType primitiveType="CHAR" length="0" precision="0" scale="0" />
                    </element>
                    <element name="LEN">
                      <inlineType primitiveType="CHAR" length="0" precision="0" scale="0" />
                    </element>
                    <element name="CITY2">
                      <inlineType primitiveType="CHAR" length="0" precision="0" scale="0" />
                    </element>
                    <element name="F">
                      <inlineType name="INTEGER" primitiveType="INTEGER" length="0" precision="0" scale="0" />
                    </element>
                    <elementFilter elementName="F">
                      <valueFilter xsi:type="Column:SingleValueFilter" including="true" value="1" />
                    </elementFilter>
                    <input>
                      <viewNode xsi:type="View:JoinNode">#/0/Join_1</viewNode>
                      <mapping xsi:type="Type:ElementMapping" targetName="CITY" sourceName="CITY" />
                      <mapping xsi:type="Type:ElementMapping" targetName="ROAD_ID" sourceName="ROAD_ID" />
                      <mapping xsi:type="Type:ElementMapping" targetName="LEN" sourceName="LEN" />
                      <mapping xsi:type="Type:ElementMapping" targetName="CITY2" sourceName="CITY2" />
                      <mapping xsi:type="Type:ElementMapping" targetName="F" sourceName="F" />
                    </input>
                  </viewNode>';
                  

                  --注意命名空间...

                  --Beware of the namespace...

                  WITH XMLNAMESPACES('dummy' AS xsi)
                  SELECT 
                  Tab.Col.value('../@name','nvarchar(50)') as ViewNode,
                  Tab.Col.value('@name','nvarchar(50)') as Name,
                  Tab.Col.value('(endUserTexts/@label)[1]','nvarchar(50)') as Label,  
                  Tab.Col.value('(inlineType/@primitiveType)[1]','nvarchar(50)') as PrimitveType, 
                  Tab.Col.value('(inlineType/@length)[1]','nvarchar(50)') as Length,  
                  Tab.Col.value('(inlineType/@precision)[1]','nvarchar(50)') as Precision,    
                  Tab.Col.value('(inlineType/@scale)[1]','nvarchar(50)') as Scale,
                  Tab.Col.value('@elementName','nvarchar(50)') as filter_elementName,
                  Tab.Col.value('(valueFilter/@xsi:type)[1]','nvarchar(50)') as filter_ValueFilterType,
                  Tab.Col.value('(valueFilter/@including)[1]','bit') as filter_Including,
                  Tab.Col.value('(valueFilter/@value)[1]','nvarchar(50)') as filter_value
                  FROM @x.nodes('/viewNode/*[substring(local-name(),1,7)="element"]') AS Tab(Col)
                  

                  这篇关于从父节点 xml sql server 检索所有子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从 SQL Server 表以正确的语法生成 XML 下一篇:使用 Any(,) 分隔符在单列中检索的 XML 值 (2)

                  相关文章

                  最新文章

                  1. <small id='Bwuik'></small><noframes id='Bwuik'>

                  2. <tfoot id='Bwuik'></tfoot>

                      <legend id='Bwuik'><style id='Bwuik'><dir id='Bwuik'><q id='Bwuik'></q></dir></style></legend>
                      <i id='Bwuik'><tr id='Bwuik'><dt id='Bwuik'><q id='Bwuik'><span id='Bwuik'><b id='Bwuik'><form id='Bwuik'><ins id='Bwuik'></ins><ul id='Bwuik'></ul><sub id='Bwuik'></sub></form><legend id='Bwuik'></legend><bdo id='Bwuik'><pre id='Bwuik'><center id='Bwuik'></center></pre></bdo></b><th id='Bwuik'></th></span></q></dt></tr></i><div id='Bwuik'><tfoot id='Bwuik'></tfoot><dl id='Bwuik'><fieldset id='Bwuik'></fieldset></dl></div>
                        <bdo id='Bwuik'></bdo><ul id='Bwuik'></ul>