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

  • <tfoot id='NQf9m'></tfoot>

        <legend id='NQf9m'><style id='NQf9m'><dir id='NQf9m'><q id='NQf9m'></q></dir></style></legend>

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

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

        替代祖先或自我(或选择树中具有特定子节点的所

        时间:2023-06-05

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

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

                  本文介绍了替代祖先或自我(或选择树中具有特定子节点的所有节点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试识别树中通向特定节点的所有节点.

                  我正在尝试通过 MSSQL XML (2005) 或 ASP 经典中的 Microsoft.XMLDOM 来实现这一点.

                  我知道 XPATH 的逻辑,但 SQL Server 不支持 ancestor-or-self 轴,而且 XMLDOM 似乎在 :: 符号上窒息..

                  当我在 XPATH 测试器中测试时有效的 xpath 是

                  //static[@id=6]/ancestor-or-self::static

                  我的 XML(在 sql server 中递归生成)看起来像

                  <static id="1" title="some title 1"/><static id="2" title="一些标题 2"><儿童><static id="3" title="some title 3"/><static id="4" title="some title 4"><儿童><static id="5" title="some title 5"/><static id="6" title="some title 6"/></儿童></静态></儿童></静态><static id="7" title="some title 7"/></root>

                  XPATH 应该以任何顺序选择 id 为 (2,4,6) 的节点,因此我可以为所有节点添加一个属性..

                  这是一个菜单系统,其中我只知道选定的叶子,并且需要将通向它的所有节点标记为 hilited..

                  如果您能在克服 XMLDOM 阻塞方面得到任何帮助,我将不胜感激(运行 xml.documentElement.selectNodes("//static[@id=6]/ancestor-or-self::static") 产生以下错误:Expected token 'eof' found ':'.//static[@id=6]/ancestor-or-self-->:<--:static)

                  或者寻找替代解决方案.也许在任何深度找到包含特定节点(id = 6)的所有节点..

                  解决方案

                  在 W2K3 上运行,使用 IIS6 我测试了 MSXML2.XMLDomDocument.4.0 版本.

                  Dim XMLDom ''# As MSXML2.DOMDocument40Set XMLDom = CreateObject("MSXML2.DOMDocument.4.0")调用 XMLDom.setProperty("SelectionLanguage", "XPath")调用 XMLDom.loadXML( {文档如上所述 - 原始 xml 文档中的错误))Dim originalQuery ''# As StringoriginalQuery = "//static[@id=6]/ancestor-or-self::static"Dim replacementQuery ''# As StringreplaceQuery = "//static[descendant::static[@id=6] or @id=6]"Dim XmlElemList ''# As MSXML2.IXMLDOMNodeList设置 XmlElemList = XMLDom.documentElement.selectNodes(originalQuery)Dim XmlElemList2 ''# As MSXML2.IXMLDOMNodeList设置 XmlElemList2 = XMLDom.documentElement.selectNodes(replacementQuery)Dim XmlElem ''# 作为 MSXML2.IXMLDOMElementCall Response.Write("Using original query : '" & originalQuery & "' (" & XmlElemList.Length & ")<br>")对于 XmlElemList 中的每个 XmlElem调用 Response.Write("XmlEntry : " & XmlElem.getAttribute("id") & "
                  ")调用 Response.Write("****
                  ")下一个Call Response.Write("使用替换查询:'" & replacementQuery & "' (" & XmlElemList2.Length & ")<br>")对于 XmlElemList2 中的每个 XmlElem调用 Response.Write("XmlEntry : " & XmlElem.getAttribute("id") & "
                  ")调用 Response.Write("****
                  ")下一个

                  I am trying to identify all the nodes in a tree that lead to a specific node.

                  I am trying to accomplish this through either MSSQL XML (2005) or by the Microsoft.XMLDOM in ASP classic.

                  I know the logic with XPATH but SQL Server does not support the ancestor-or-self axis and XMLDOM seems to choke on the :: notation..

                  The xpath that works when i test it in XPATH testers is

                  //static[@id=6]/ancestor-or-self::static
                  

                  my XML (generated recursively in sql server) looks like

                  <root>
                    <static id="1" title="some title 1" />
                    <static id="2" title="some title 2">
                       <children>
                          <static id="3" title="some title 3" />
                          <static id="4" title="some title 4">
                            <children>
                              <static id="5" title="some title 5" />
                              <static id="6" title="some title 6" />
                            </children>
                          </static>
                       </children>
                    </static>
                    <static id="7" title="some title 7" />
                  </root>
                  

                  the XPATH should select nodes with id (2,4,6) in any order, so i can add an attribute to all of them ..

                  This is for a menu system, where i only know the selected leaf, and need to mark as hilited all the nodes leading to it..

                  I would appreciate any assistance in either overcoming the XMLDOM choking (running xml.documentElement.selectNodes("//static[@id=6]/ancestor-or-self::static") produces the following error: Expected token 'eof' found ':'. //static[@id=6]/ancestor-or-self-->:<--:static)

                  or with finding an alternative solution. Maybe finding all nodes that contain the specific node (with id = 6 ) at any depth..

                  解决方案

                  Running on W2K3, using IIS6 i tested the MSXML2.XMLDomDocument.4.0 version.

                  Dim XMLDom ''# As MSXML2.DOMDocument40
                  
                  Set XMLDom = CreateObject("MSXML2.DOMDocument.4.0")
                  Call XMLDom.setProperty("SelectionLanguage", "XPath")
                  
                  Call XMLDom.loadXML( {document as described above - mistakes in original xml doc)
                  )
                  
                  
                  Dim originalQuery ''# As String
                  originalQuery = "//static[@id=6]/ancestor-or-self::static"
                  
                  Dim replacementQuery ''# As String
                  replacementQuery = "//static[descendant::static[@id=6] or @id=6]"
                  
                  
                  Dim XmlElemList ''# As MSXML2.IXMLDOMNodeList
                  Set XmlElemList = XMLDom.documentElement.selectNodes(originalQuery)
                  
                  Dim XmlElemList2 ''# As MSXML2.IXMLDOMNodeList
                  Set XmlElemList2 = XMLDom.documentElement.selectNodes(replacementQuery)
                  
                  Dim XmlElem ''# As MSXML2.IXMLDOMElement
                  Call Response.Write("Using original query : '" & originalQuery & "' (" & XmlElemList.Length & ")<br>")
                  For Each XmlElem In XmlElemList
                      Call Response.Write("XmlEntry : " & XmlElem.getAttribute("id") & "<br>")
                      Call Response.Write("****<br>")
                  Next
                  
                  Call Response.Write("Using replacement query : '" & replacementQuery & "' (" & XmlElemList2.Length & ")<br>")
                  For Each XmlElem In XmlElemList2
                      Call Response.Write("XmlEntry : " & XmlElem.getAttribute("id") & "<br>")
                      Call Response.Write("****<br>")
                  Next
                  

                  这篇关于替代祖先或自我(或选择树中具有特定子节点的所有节点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从 sum 中删除一个 xml 节点,在 XPath 到 SQL Server 下一篇:如何从sql中的给定xml中获取'/'分隔的节点

                  相关文章

                  最新文章

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

                      <legend id='4qA4g'><style id='4qA4g'><dir id='4qA4g'><q id='4qA4g'></q></dir></style></legend>