我想在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