Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:12:46+00:00 2026-06-04T00:12:46+00:00

I’ve got a function api_request which takes API method as an argument, and returns

  • 0

I’ve got a function api_request which takes API method as an argument, and returns XMLTextReader

Shared Function api_request(method As String) As XmlTextReader
request_text = method & ".xml"
 url = "https://api.vk.com/method/" & request_text & "&access_token=" & token
 Return New XmlTextReader(url)
End Function

I call this function from different places to make request to site API and depending on the method results are parsed very differently.

So in each method I have something like this:

Dim s As Xml.XmlReader = api_request("users.get")
While s.Read
        If s.NodeType = XmlNodeType.Element Then
          If s.Name = "user" Then
              curr_user=s.ReadElementContentAsString            
          ElseIf s.Name = "error" Then
             error_handler(s, "user.get")
          End If
       End If
End While

As you may see, I have the code ElseIf s.Name = "error" Then error_handler(s, "user.get"). This is because when error happens, server always returns something like this:

<error>
<error_code>4</error_code>
<error_msg>Incorrect signature</error_msg>
</error>

This is parsed in error_handler Sub, and depending on the error following actions are chosen.

This code works, but I have to check if I encounter error like that ElseIf s.Name = "error" every time, though all the methods call the api_request function. Is it possible to check for error in api_request function before returning the Reader? The problem is if I start reading xml there, and there isn’t an error, I can’t anyhow position the Reader to the start.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:12:48+00:00Added an answer on June 4, 2026 at 12:12 am

    Since you can’t change your position with an XmlTextReader, the only other solution would be to load the entire XML document into memory. Presumably the XmlTextReader is going to download the entire XML file into memory when it first reads it anyway, so any performance hit should be negligible. I would suggest something like this:

    Shared Function api_request(ByVal method As String) As XmlDocument
        request_text = method & ".xml"
        url = "https://api.vk.com/method/" & request_text & "&access_token=" & token
        Dim doc As XmlDocument = New XmlDocument()
        doc.Load(New XmlTextReader(url))
        Dim node As XmlNode = doc.SelectSingleNode("error")
        If node IsNot Nothing Then
            Try
                Dim errorCode As Integer = Integer.Parse(node.SelectSingleNode("error_code").InnerText)
                Dim errorMessage As String = node.SelectSingleNode("error_msg").InnerText
                errorHandler(errorCode, errorMessage, method)
                doc = Nothing
            Catch ex As Exception
                Throw New Exception("Improperly formatted error response: " + doc.InnerXml, ex)
            End Try
        End If
        Return doc
    End Function
    

    And then in the method that calls api_request, do something like this:

        Dim doc As XmlDocument = api_request("users.get")
        If doc IsNot Nothing Then
            For Each node As XmlNode In doc.SelectNodes("path_to_user/user")
                curr_user = node.InnerText
            Next
        End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.