XML reader

  • Thread starter Thread starter Maileen
  • Start date Start date
M

Maileen

Hi,

I have a XML file which consists of several elements and I would like to
retrieve the value of 1 element particularly.

for example :

....
<Database_Location>
C:\test\db1.mdb
</Database_Location>

I try to get the value of "C:\test\db1.mdb" with the following code :

While XmlRead.Read
If (XmlNodeType.Element) Then
If (XmlRead.Name = "Database_Location") Then
MsgBox("before : " & XmlRead.Value)
End If
End If
End While

but every time I get the Value empty...why ?

thanks a lot,
Maileen
 
try:

Dim tmpXML As New Xml.XmlDocument
Dim database_location As String
tmpXML.Load(licensefile)
database_location = tmpXML.GetElementsByTagName("Database_Location").Item(0).InnerText
 
Maileen,

You can try this sample I made once as well
\\\\
Dim xmlString As String = "<department>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.StringReader(xmlString)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
'or just in this case doc.LoadXML(xmlString)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "employee" Then
MessageBox.Show(reader.GetAttribute("name"))
End If
End Select
End While
///

Cor
 
Maileen wrote:

I have a XML file which consists of several elements and I would like to
retrieve the value of 1 element particularly.

for example :

...
<Database_Location>
C:\test\db1.mdb
</Database_Location>

I try to get the value of "C:\test\db1.mdb" with the following code :

While XmlRead.Read
If (XmlNodeType.Element) Then
If (XmlRead.Name = "Database_Location") Then
MsgBox("before : " & XmlRead.Value)

You need to use
XmlRead.ReadElementString()
to get at the content of the Element node.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top