An object-oriented programming language developed by Microsoft that can be used in .NET.
Try a modification:
_Dim xmlRoot As XmlElement = xmlDoc.SelectSingleNode("//myfile/file_map/open_as_[@ID='csv']")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
So first of all, please excuse that I may not have my xml terminology correct. Hopefully this is self explanatory!
I have some code that successfully can add an element to an xml file as below:
Sub add_element(xmlfile, element_name, to_add)
Dim xmlDoc As New XmlDocument
xmlDoc.Load(xmlfile)
Dim xmlRoot As XmlElement = xmlDoc.SelectSingleNode(//myfile/file_map/open_as)
Dim xmlChild As XmlElement = xmlDoc.CreateElement(element_name)
xmlChild.InnerText = to_add
xmlRoot.AppendChild(xmlChild)
Try
xmlDoc.Save(xmlfile)
Catch ex As Exception
MsgBox("Exception: " & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
The problem I have is when the parent contains an attribute (think thats the terminology!) such as:
<open_as ID="txt">
What I want to do is add an extension to the <open_as ID="csv"> in the xml listed below. If I use the code above, it just adds to the first 'open as', and I dont know how to define the specific 'open as' to be 'csv'
How can I modify my code to specify the 'csv' open as below and add an element to it???
<myfile>
<notes>notes here>
<file_map>
<open_as ID="txt">
<extension>abc</extension>
<extension>def</extension>
</open_as>
<open_as ID="csv">
<extension>ghi</extension>
<extension>jkl</extension>
</open_as>
</file_map>
</myfile>
An object-oriented programming language developed by Microsoft that can be used in .NET.
Answer accepted by question author
Try a modification:
_Dim xmlRoot As XmlElement = xmlDoc.SelectSingleNode("//myfile/file_map/open_as_[@ID='csv']")