How to apply the XPath function 'substring-after'

前端 未结 4 1137
陌清茗
陌清茗 2020-12-01 16:18

What is the XPath expression that I would use to get the string following \'HarryPotter:\' for each book.

ie. Given this XML:




        
4条回答
  •  被撕碎了的回忆
    2020-12-01 16:47

    In your XML you've got no space between Harry Potter but in your XQuery you've got a space. Just make it match and presto, you'll get data back...

        Dim xml = 
                      HarryPotter:Chamber of Secrets
                      HarryPotter:Prisoners in Azkabahn
                      MyDummyBook:Dummy Title
                  
    
        Dim xdoc As New Xml.XmlDocument
        xdoc.LoadXml(xml.ToString)
    
        Dim Nodes = xdoc.SelectNodes("/bookstore/book/text()[substring-after(., 'HarryPotter:')]")
    
        Dim Iter = Nodes.GetEnumerator()
        While Iter.MoveNext
            With DirectCast(Iter.Current, Xml.XmlNode).Value
                Console.WriteLine(.Substring(.IndexOf(":") + 1))
            End With
        End While
    

提交回复
热议问题