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 5976415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:13:30+00:00 2026-05-22T21:13:30+00:00

When I try to parse a response from a certain REST API, I’m getting

  • 0

When I try to parse a response from a certain REST API, I’m getting an XmlException saying “Data at the root level is invalid. Line 1, position 1.” Looking at the XML it looks fine, but then examining the first character I see that it is actually a zero-width no-break space (character code 65279 or 0xFEFF).

Is there any good reason for that character to be there? Maybe I’m supposed to be setting a different Encoding when I make my request? Currently I’m using Encoding.UTF8.

I’ve thought about just removing the character from the string, or asking the developer of the REST API to fix it, but before I do either of those things I wanted to check if there is a valid reason for that character to be there. I’m no unicode expert. Is there something different I should be doing?

Edit: I suspected that it might be something like that (BOM). So, the question becomes, should I have to deal with this character specially? I’ve tried loading the XML two ways and both throw the same exception:

public static User GetUser()
{
    WebClient req = new WebClient();
    req.Encoding = Encoding.UTF8;
    string response = req.DownloadString(url);

    XmlSerializer ser = new XmlSerializer(typeof(User));
    User user = ser.Deserialize(new StringReader(response)) as User;

    XElement xUser = XElement.Parse(response);

    ...

    return user;
}
  • 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-05-22T21:13:31+00:00Added an answer on May 22, 2026 at 9:13 pm

    Instead of using Encoding.UTF8, create your own UTF-8 encoder, using the constructor overload that lets you specify whether or not the BOM is to be emitted:

    req.Encoding = new UTF8Encoding( false ) ; // omit the BOM
    

    I believe that will do the trick for you.

    Amended to Note: The following will work:

    public static User GetUser()
    {
      WebClient req   = new WebClient();
      req.Encoding    = Encoding.UTF8;
      byte[] response = req.DownloadData(url);
    
      User instance ;
    
      using ( MemoryStream stream = new MemoryStream(buffer) )
      using ( XmlReader    reader = XmlReader.Create( stream ) )
      {
        XmlSerializer serializer = new XmlSerializer(typeof(User)) ;
        instance = (User) serializer.Deserialize( reader ) ;
      }
    
      return instance ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having received the following response from Foursquare, when I try to parse it, I
I'm try to parse this xml, but c# keeps throwing an exception saying it
I'm trying to parse a web service response using SAXParser and get certain values,
I try to get parse JSON response for the following link: https://graph.facebook.com/feed/?ids=135395949809348,149531474996&access_token= The response
I am getting response from server side in the form of json array.I need
When I try to retrieve information from Google weather API with the following URL,
I am using JQuery, FLXHR for getting the data from Cross Browser. Below is
I try to parse RSS chaanal with simple-rss lib. Unfortunately I got a lot
Is there a way to tell ifort or gfortran to just try to parse
I'm trying to parse a webpage using Java with URLConnection. I try to set

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.