• <small id='8FHbT'></small><noframes id='8FHbT'>

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

    1. <tfoot id='8FHbT'></tfoot>

        <legend id='8FHbT'><style id='8FHbT'><dir id='8FHbT'><q id='8FHbT'></q></dir></style></legend>

      1. 删除 SQL Server 中不同级别的空 XML 标记

        时间:2023-06-05
        <tfoot id='yjwbV'></tfoot>

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

              <tbody id='yjwbV'></tbody>
              <bdo id='yjwbV'></bdo><ul id='yjwbV'></ul>
              <i id='yjwbV'><tr id='yjwbV'><dt id='yjwbV'><q id='yjwbV'><span id='yjwbV'><b id='yjwbV'><form id='yjwbV'><ins id='yjwbV'></ins><ul id='yjwbV'></ul><sub id='yjwbV'></sub></form><legend id='yjwbV'></legend><bdo id='yjwbV'><pre id='yjwbV'><center id='yjwbV'></center></pre></bdo></b><th id='yjwbV'></th></span></q></dt></tr></i><div id='yjwbV'><tfoot id='yjwbV'></tfoot><dl id='yjwbV'><fieldset id='yjwbV'></fieldset></dl></div>
              • <legend id='yjwbV'><style id='yjwbV'><dir id='yjwbV'><q id='yjwbV'></q></dir></style></legend>
                • 本文介绍了删除 SQL Server 中不同级别的空 XML 标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我使用 FOR XML EXPLICIT 来联合将一些 SQL 表信息转换为 XML 文件.一切正常,但我在结果中有很多不同级别的空标签.我想删除所有空标签,但保留每个组的顶级.这是我的意思的一个例子:

                  I am using FOR XML EXPLICIT to union to convert some SQL table info into an XML file. It's all working, but I have loads of empty tags in the results, at all sorts of different levels. I would like to remove all the empty tags, but keep the top level for each group. Here's an example of the sort of thing I mean:

                  使用这个无意义的 XML 示例,我可以使用 .modify xquery 删除底层空节点:

                  Using this example bit of nonsense XML, I can remove the bottom level empty nodes with a .modify xquery:

                  DECLARE @XML XML = 
                  '<Whatever>
                    <GlassesTypes>
                        <GlassesType />
                    </GlassesTypes>
                    <ExpressionOfJoy>
                        <FellOver>Y</FellOver>
                    </ExpressionOfJoy>
                    <Flights>
                      <Flight>
                        <Bookings>
                          <Booking>
                            <Segments>
                              <Segment />
                            </Segments>
                          </Booking>
                        </Bookings>
                      </Flight>
                    </Flights>
                  </Whatever>'
                  
                  SELECT @XML as Before
                  
                  SET  @Xml.modify('delete //*[not(node())]');
                  
                  SELECT @XML AS After
                  

                  这完全符合我对GlassesTypes"的要求,但Flights"中仍然存在一些级别的空节点.我可以为每个级别一遍又一遍地重复相同的修改命令,直到只显示航班",但这样做会删除眼镜类型"空占位符:

                  This has done exactly what I want with 'GlassesTypes', but there are still levels of empty nodes in 'Flights'. I could repeat the same modify command over and over for each level to get up to the point where only 'Flights' is displayed, but doing so will delete the 'GlassesTypes' empty placeholder:

                  DECLARE @XML XML = 
                  '<Whatever>
                    <GlassesTypes>
                        <GlassesType />
                    </GlassesTypes>
                    <ExpressionOfJoy>
                        <FellOver>Y</FellOver>
                    </ExpressionOfJoy>
                    <Flights>
                      <Flight>
                        <Bookings>
                          <Booking>
                            <Segments>
                              <Segment />
                            </Segments>
                          </Booking>
                        </Bookings>
                      </Flight>
                    </Flights>
                  </Whatever>'
                  
                  SELECT @XML as Before
                  
                  SET  @Xml.modify('delete //*[not(node())]');
                  SET  @Xml.modify('delete //*[not(node())]');
                  SET  @Xml.modify('delete //*[not(node())]');
                  SET  @Xml.modify('delete //*[not(node())]');
                  SET  @Xml.modify('delete //*[not(node())]');
                  
                  SELECT @XML AS After
                  

                  有什么方法可以删除所有空节点,直到倒数第二个空节点,而不管一个组包含多少层?理想的结果是这样的:

                  Is there any way in which I can delete all empty nodes, until the penultimate empty node, regardless of how many levels a group contains? The ideal result would be this:

                  <Whatever>
                    <GlassesTypes />
                    <ExpressionOfJoy>
                        <FellOver>Y</FellOver>
                    </ExpressionOfJoy>
                    <Flights />
                  </Whatever>
                  

                  在这个例子中,只有Whatever"标签,但在真实数据中,可能有几个重复的,都包含不同级别的信息,包含在一个根标签或等效标签中.

                  In this example, there is only 'Whatever' tag, but in the real data, there might be several repeated, all with different levels of information, encompassed by a root tag or equivalent.

                  非常感谢任何帮助!

                  谢谢,标记

                  推荐答案

                  您可以将您的空"版本定义为不包含任何后代属性或文本节点,而不是不包含任何后代节点.然后通过仅选择其子项的后代来保留 的子项:

                  You can define your version of "empty" as not containing any descendant attribute or text nodes, instead of as not containing any descendant nodes. Then retain children of <Whatever> by only selecting descendants of its children:

                  /Whatever/*//*[empty(.//text() | .//attribute())]
                  

                  这篇关于删除 SQL Server 中不同级别的空 XML 标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何查询 SQL Server XML 列并返回特定节点的所有值 下一篇:使用 xquery 转换为 html?

                  相关文章

                  最新文章

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

                    • <bdo id='qnvLT'></bdo><ul id='qnvLT'></ul>