Results 1 to 2 of 2

Thread: how shall i read xml file from ashx in javascript

Threaded View

  1. #1

    Thread Starter
    Member dionisis's Avatar
    Join Date
    Feb 2011
    Posts
    52

    how shall i read xml file from ashx in javascript

    Hi guys,

    On my aspx page I use google maps. On dragend event I want to load latlng points from my sql database. I am trying to find some code examples but no luck. I will write down what I’ve done so far and please feel free to guide me on any solution you might have, or on any correction on my current code.

    I read as much I could at these days and I decided to go on ashx control which wil return an xml file. At my first attempt I will kepp it as simple as I can, to realize how I will go through this.

    Code:
    Imports System.Web
    Imports System.Web.Services
    
    
    Public Class getLocs
        Implements System.Web.IHttpHandler
    
        Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
            Dim App As New myApp
            context.Response.Clear()
            context.Response.ContentType = "text/xml"
            context.Response.ContentEncoding = System.Text.Encoding.UTF8
            context.Response.Write(getXml())
            context.Response.End()
    
        End Sub
    
        ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property
    
        Public Function getXml() As System.Xml.XmlDocument
            Dim xmlr As System.Xml.XmlReader = Nothing
            Dim xmlrDoc As New System.Xml.XmlDocument
            
    
            Dim cn As New System.Data.SqlClient.SqlConnection()
            cn.ConnectionString = _
            "data source=.\SQLEXPRESS;initial catalog=glxxx;" & _
            "User ID=xxx;Password=xxxx"
            cn.Open()
    
            Dim cmd As New System.Data.SqlClient.SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "SELECT * FROM leta_loc FOR XML RAW('marker'),ROOT('markers')"
    
            xmlr = cmd.ExecuteXmlReader()
            xmlr.ReadOuterXml()
            xmlrDoc.Load(xmlr)
            MsgBox(xmlrDoc.OuterXml.ToString)
            Return xmlrDoc
        End Function
    End Class

    a) Do I have to return the xmlreader or xmldocument? I want as I described to catch the xml in javascript on the dragend event of google maps.

    b) How am I gonna read the result xml in javascript?

    Thank you
    Last edited by dionisis; Oct 21st, 2012 at 05:26 AM. Reason: edit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width