|
-
Aug 3rd, 2004, 11:18 PM
#1
Thread Starter
Fanatic Member
XML file searching and updating
Ok I'm learning this more and more every single day and I've about got it. But I have a couple questions.
I am now successfully able to load an xml document, point to a node, capture and display the value of that node, and change the value of the node, using this code:
Code:
Private Sub xmlChange()
Dim DS As New DataSet()
'loads xml file into dataset
DS.ReadXml("c:\inetpub\wwwroot\xmlTest\xmlemp.xml")
DS.Tables(0).Rows(0).Item("Name") = "NEW VALUE"
' write the xml file
DS.WriteXml("c:\inetpub\wwwroot\xmlTest\xmlemp.xml")
End Sub
As you can see, I'm using a dataset to accomplish the above.
Another way I'm trying this is with XPath, which I'm still learning. This code pulls the value of whatever node I choose, but I have to know the name of the node beforehand (i think):
Code:
Public Sub xmlRecord()
Dim xpathdoc As XPath.XPathDocument
Dim xmlNav As XPath.XPathNavigator
Dim xmlITI As XPath.XPathNodeIterator
xpathdoc = New XPath.XPathDocument("C:\Inetpub\wwwroot\xmlTest\xmlemp.xml")
xmlNav = xpathdoc.CreateNavigator
xmlITI = xmlNav.Select("/NewDataSet/Table/Department")
While (xmlITI.MoveNext())
xmlTextbox.Text = xmlITI.Current.Name + " : " + xmlITI.Current.Value
End While
End Sub
Now using these this method, I can pull any values I want as long as I know the node.
But what I am trying to accomplish is this:
I want to search an XML document, preferably WITHOUT knowing which node it will be in, then replace the value I'm looking for with another value I will have saved in a variable. Which of these two methods (dataset or XPaths) will be easier to accomplish this, and how can I search and replace the string I want without knowing which node it is in?
Thank you for all your help! I've learned alot about this in the past few days!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|