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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

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 SotoRetiredCommented:
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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Did my last post work out for you? Please update.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.