当前位置 : 主页 > 编程语言 > c语言 >

如何确定XmlNode是否具有特定属性?

来源:互联网 收集:自由互联 发布时间:2021-06-24
我想在sub中放置一个if条件,告诉它在属性TEST =“test.doc”的xml节点STORE不存在时运行.任何建议都会很棒.我是vb的新手. Sub InsertNode(ByVal doc As XmlDocument) Dim City As XmlNode = doc.DocumentElement Dim
我想在sub中放置一个if条件,告诉它在属性TEST =“test.doc”的xml节点STORE不存在时运行.任何建议都会很棒.我是vb的新手.

Sub InsertNode(ByVal doc As XmlDocument)   
    Dim City As XmlNode = doc.DocumentElement

    Dim Location As XmlElement = doc.CreateElement("store")
    Location.SetAttribute("test", "test.doc")

    Dim books As XmlElement = doc.CreateElement("books")
    books.InnerXml = "New Words"
    Location.AppendChild(books)

    City.AppendChild(store)
End Sub 'InsertNode

XML文件的示例

<city>
    <store test="test.doc">
        <books>
        "New Words" 
        </books>
    </store>
</city>
尝试类似的东西:

If Not doc.SelectSingleNode("//store[@test='test.doc']") Is Nothing Then
    Exit Sub
End If
网友评论