I would like to place an if condition within the sub that will tell it to run when the xml node STORE with attribute TEST="test.doc" does not exist. Any suggestions would be great. I'm new to 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
<city>
    <store test="test.doc">
        <books>
        "New Words" 
        </books>
    </store>
</city>
                Try something like that :
If Not doc.SelectSingleNode("//store[@test='test.doc']") Is Nothing Then
    Exit Sub
End If
                        Assuming that Location is the node you want to check to see if your attribute exists:
If Location.Attributes.ItemOf("test") Is Nothing Then
    'Attribute doesnt exist
Else
    'Attribute does exist
End If
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With