PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET Reading XML Data

Reply

Reading XML Data

 
Thread Tools Rate Thread
Old 09-10-2003, 03:37 PM   #1
Arvind P Rangan
Guest
 
Posts: n/a
Default Reading XML Data


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


  Reply With Quote
Old 10-10-2003, 03:00 AM   #2
Fergus Cooney
Guest
 
Posts: n/a
Default Re: Reading XML Data

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


  Reply With Quote
Old 10-10-2003, 07:16 AM   #3
Arvind P Rangan
Guest
 
Posts: n/a
Default Re: Reading XML Data

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

Regards
aRvind.
"Fergus Cooney" <filter-1@tesco.net> wrote in message
news:eBzjvJtjDHA.2436@TK2MSFTNGP09.phx.gbl...
> 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
>
>



  Reply With Quote
Old 10-10-2003, 10:19 AM   #4
Cor
Guest
 
Posts: n/a
Default Re: Reading XML Data

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
& "'")

> End If
> End Select




  Reply With Quote
Old 10-10-2003, 10:40 AM   #5
Arvind P Rangan
Guest
 
Posts: n/a
Default Re: Reading XML Data

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
"Cor" <non@non.com> wrote in message
news:3f8679ad$0$28432$48b97d01@reader21.wxs.nl...
> 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
> & "'")
>
> > End If
> > End Select

>
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off