(Type your message here)
Pretty sophisticated forum for an xml/vb .net newby ... need to one loop thru each successive node to grap info from child nodes to populate variables. Here's a couple of xml files I have tried on this project (and I can change it if I formed it incorrectly).
-
- c:\TestSource
- c:\TestSourceAgain
and also tried xml this way:
c:\testSourcec:\testTargetc:\testSourceAgainc:\testTargetAgain
and here's the code that almost does it -- I've done variations on it trying to get the info (source and target) in one turn around the block 'cause this stuff cycles thru the source over and over again when what I need is for it to find the source and target info together in one turn (then I'll make it perfom an action); then another target and source (and I'll run it thru its paces again).
'===================WORKS!!!! A LITTLE!!!! ======================
'For Each node In doc.DocumentElement
' '''put sourcepath node into variable to use as relative path
' Dim SourcePath As String
' Dim TargetPath As String
' Dim sourcepaths As XmlNodeList
' sourcepaths = doc.GetElementsByTagName("Source")
' Dim sourcenode As XmlNode
' For Each sourcenode In sourcepaths
' SourcePath = sourcenode.ChildNodes(0).Value
' lblStatus.Text = SourcePath.ToString
' Next
' Dim targetpaths As XmlNodeList
' targetpaths = doc.GetElementsByTagName("Target")
' Dim targetnode As XmlNode
' For Each targetnode In targetpaths
' TargetPath = targetnode.ChildNodes(0).Value
' lblStatus.Text = TargetPath.ToString
' Next
'Next
======================
thanks, for any and all help on this!
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hi,
I am not that sure what you want to do. But it seems that you want to get the values from the sourcepath and targetpath right???
Example:
To get the values, this is how you can achieve it.
I assume you already select the Device element... if not this is how you do that!
dim xmlDocument as XmlDocument
dim node as XmlNodeList
node = xmlDocument.SelectNodes("Device")
.....
'retrieves the values of each node
Public Sub GetCommandNode(ByVal node As XmlNode, ByRef type As String, ByRef name As String, ByRef id As Short, ByRef length As Int32)
Try
type = node.SelectSingleNode("Type").InnerText()
name = node.SelectSingleNode("Name").InnerText()
id = XmlConvert.ToInt16(node.SelectSingleNode("Connection/ID").InnerText())
length = XmlConvert.ToInt32(node.SelectSingleNode("Connection/Length").InnerText())
Catch ex As Exception
Throw New ApplicationException(ex.Message)
End Try
End Sub
Hope it helps you somehow.
Cheers.
mibuytPosted Mar 17, 2005, 7:47 PM
ablountPosted Mar 17, 2005, 5:18 PM
mibuytPosted Mar 16, 2005, 8:23 PM