Reading XML Data

  • Thread starter Arvind P Rangan
  • Start date
A

Arvind P Rangan

Hi,
Code:
Dim xmlstring As String = "http://localhost/log.xml"
Dim xmlreads As XmlTextReader = New XmlTextReader(xmlstring)
Dim id As Integer = 0
Try
While xmlreads.Read()
Select Case xmlreads.NodeType
Case XmlNodeType.Element
If InStr(xmlreads.Name, "id") > 0 Then
Response.Write(" " + xmlreads.Name + "='" +
xmlreads.Value + "'")
End If

End Select
End While
'Response.Write(id.ToString)
Catch es As Exception
If Not InStr(es.Message, "404") = 0 Then
Response.Write("File Not Found!!!!" & InStr(es.Message,
"404"))
Else
Response.Write(InStr(es.Message, "404") & es.Message)
End If
End Try

XMLFILE:
<?xml version="1.0" encoding="utf-8" ?>
<LOG xmlns="log.xsd">
<id>1</logid>
<logdatetime>2002-05-30T09:00:00</logdatetime>
<eventtitle>New</eventtitle>
<eventdesc>adsadsadsad </eventdesc>
<eventby>arangan</eventby>
<id>1</logid>
<logdatetime>2002-05-30T09:00:00</logdatetime>
<eventtitle>New</eventtitle>
<eventdesc>adsadsadsad </eventdesc>
<eventby>arangan</eventby>
</LOG>

ERROR: id='' id='' ???? why am i not getting the values ????
Pls Help me

Thanks
Arvind
 
F

Fergus Cooney

Hi Arvind,

I haven't examined it deeply but a quick glance showed me:

The following element invalidates the Xml.
<id>1</logid>

You need
<id>1</id>

You have two sets of
<id>1</id>
<logdatetime>2002-05-30T09:00:00</logdatetime>
<eventtitle>New</eventtitle>
<eventdesc>adsadsadsad </eventdesc>
<eventby>arangan</eventby>

I think you might want these to enclosed within a further element:
<logevent>
<id>1</id>
<logdatetime>2002-05-30T09:00:00</logdatetime>
<eventtitle>New</eventtitle>
<eventdesc>adsadsadsad </eventdesc>
<eventby>arangan</eventby>

</logevent>

Regards,
Fergus
 
A

Arvind P Rangan

Thanks Fergus,
Sorry, but that problem is corrected, even after that its the same problem.

Regards
aRvind.
 
C

Cor

Hi Arvind
Beside the two errors Fergus did mention already, I changed your code a
little bit, you see the two changed line without the >t beneath,
I hope that gives the result you want?
Cor
Dim xmlstring As String = "http://localhost/log.xml"
Dim xmlreads As XmlTextReader = New XmlTextReader(xmlstring)
Dim id As Integer = 0
Try
While xmlreads.Read()
Select Case xmlreads.NodeType
Case XmlNodeType.Element
If InStr(xmlreads.Name, "id") > 0 Then

xmlreads.Read()
Response.Write(" " & "Id='" & xmlreads.Value
& "'")
 
A

Arvind P Rangan

Hi Cor,
Thanks a lot i got it.
So this means that the identity tag and value tag are at two different level
and we need to moveto the next to reterive the value.

Thanks
Hope this kind of errors are marked.
ARvind
 

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

Top