Editing an .XML in VS 2005

I had this question after viewing how to update an xml file using vb.net.

How could I do this in VS 2005?
cmdolcetAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
You can replace this section of code
If node IsNot Nothing Then
	node.ChildNodes(1).InnerText = "masterEnableRetries"
End If

Open in new window

with this code
'' Check if the node exist
If node IsNot Nothing Then
    '' iterate through the collection of child nodes
	For Each child As XmlNode In node.ChildNodes
		Console.WriteLine("Tag: {0}" & vbTab & vbTab & "Text: {1}", child.Name, child.InnerText)
	Next
End If

Open in new window

0
 
Fernando SotoRetiredCommented:
Hi cmdolcet;

The solution link you posted was using Linq to XML but if I am not mistaken Linq wast not supported until Visual Studio 2008. If I am correct in my above statement you would then need to use the XmlDocument Class.
0
 
Fernando SotoRetiredCommented:
From your last thread there was a link to, [VB.NET] XML - Create and Merge Files. Edit, Add and Delete Nodes : posted by @Pawan Kumar, which should give you the steps needed to do what you need.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
cmdolcetAuthor Commented:
Fernando,

Look at his code I changed it to the following:

    Dim xd As New XmlDocument()
        xd.Load(filePath & "WU_MasterFile.xml")
        Dim nod As XmlNode = xd.SelectSingleNode("/MasterGlobal")
        If nod IsNot Nothing Then
            nod.ChildNodes(1).InnerText = "masterEnableRetries"
        Else
        End If

Open in new window


However I never return anything in the nod ????

I have attached the .xml file also.
WU_Masterfile.xml
0
 
Fernando SotoRetiredCommented:
What did you set the variable filePath to?
0
 
cmdolcetAuthor Commented:
Fernando,

I sent to to where my .xml file is located.

The single node method should look through each parent node to find the match the the tag /MasterGlobal
0
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi cmdolcet;

One issue you did not deal with is XmlNamespaces in the document, you need to use them when navigating the docment. Try this out.
'' Load the document and set the root element.  
Dim doc As XmlDocument = New XmlDocument()
doc.Load(filePath & "WU_MasterFile.xml")
Dim root As XmlNode = doc.DocumentElement 

'' Add the XmlNamespaceManager to handle XML namespace in the nodes.  
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable) 
nsmgr.AddNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/")
nsmgr.AddNamespace("a1", "http://schemas.microsoft.com/clr/nsassem/Wireless_Interface/Wireless%20Interface%2C%20Version%3D6.0.1.3%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull") 

'' Select the first node MasterGlobal    
Dim node As XmlNode = root.SelectSingleNode("descendant::SOAP-ENV:Body/a1:MasterGlobal", nsmgr)  
'' If node was found change its inner value
If node IsNot Nothing Then
	node.ChildNodes(1).InnerText = "masterEnableRetries"
End If

Open in new window

0
 
cmdolcetAuthor Commented:
Yes thank you so much for that piece of code.

What is the best way to loop through the ChildNodes and look inside each to see what value it is and if I need to change it?
0
 
Fernando SotoRetiredCommented:
Did my last post work out for you? Please update.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.