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

  • Home
  • SEARCH
  • 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 8977283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:20:08+00:00 2026-06-15T19:20:08+00:00

EDIT: Using the code provided by Jon Skeet. I get the following error: Message:

  • 0

EDIT: Using the code provided by Jon Skeet.

I get the following error:

Message: There is an error in XML document (2, 2).
Inner Exception: {"<Translator xmlns=''> was not expected."}

If it helps I can provide the code below:

Translator.cs:

public class Translator
{
    public FullBotTranslation Translation;

    public Translator()
    {
        Translation = new FullBotTranslation();
    }

    public void LoadLanguage(string language)
    {
        if (!Useful.ExistFile(System.AppDomain.CurrentDomain.BaseDirectory + "\\LanguagePacks\\" + language + ".xml"))
            language = "Francais";

        Translation = XmlSerializerHelper.Deserialize<FullBotTranslation>(System.AppDomain.CurrentDomain.BaseDirectory + "\\LanguagePacks\\" + language + ".xml");
    }


    public string GetTranslation(PhraseID phraseId)
    {
        foreach (Phrase phrase in Translation.Phrases)
        {
            if (phrase.PhraseID == phraseId)
                return phrase.PhraseString;
        }

        return "Incomplete translation...";
    }

    #region Nested type: Translation

    [Serializable]
    public class FullBotTranslation
    {
        public List<Phrase> Phrases = new List<Phrase>();
    }

    #endregion
}

Phrase.cs:

public class Phrase
{
    public PhraseID PhraseID { set;  get; }
    public string PhraseString{ set; get; } 

    public Phrase()
    {

    }
}

PhraseID.cs

[Serializable]
public enum PhraseID
{
    none,
    Button_Start,
    Button_Stop,
}

I use it like this:

Setup:

private Translator _translator;
_translator = new Translator();

Saving:

Helpers.XmlSerializerHelper.Serialize(
            System.AppDomain.CurrentDomain.BaseDirectory + "\\LanguagePacks\\" + langPackName.Text + ".xml",
            _translator);

Loading:

        _translator = new Translator(); //yes this is needed ;)

        _translator.LoadLanguage(preloadedLangCombo.SelectedItem.ToString());

When using the code above to save an XML file it outputs the following:

English.XML:

<?xml version="1.0"?>
<Translator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Translation>
    <Phrases>
      <Phrase>
        <PhraseID>none</PhraseID>
        <PhraseString>Incomplete Translation</PhraseString>
      </Phrase>
      <Phrase>
        <PhraseID>Button_Start</PhraseID>
        <PhraseString>Start</PhraseString>
      </Phrase>
      <Phrase>
        <PhraseID>Button_Stop</PhraseID>
        <PhraseString>Stop</PhraseString>
      </Phrase>
    </Phrases>
  </Translation>
</Translator>
  • 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-15T19:20:09+00:00Added an answer on June 15, 2026 at 7:20 pm

    It’s not clear what’s going wrong here – particularly because the error message doesn’t seem to match your sample XML. Your exception handling may well be hiding problems though – it’s a really bad idea to catch all exceptions like that, and you’re going to unnecessary lengths to close the streams involved. I would condense your class down to just this:

    public static class XmlSerializerHelper
    {
        public static void Serialize(String path, object @object)
        {
            using (var stream = File.Create(path))
            {
                var s = new XmlSerializer(@object.GetType());
                s.Serialize(stream, @object);
            }
        }
    
        public static T Deserialize<T>(String path)
        {
            using (var stream = File.OpenRead(path))
            {
                var s = new XmlSerializer(typeof(T));
                return (T) s.Deserialize(stream);
            }
        }
    }
    

    Now if something goes wrong, the exception will propagate out of the methods, rather than being disguised. Also, note that I’ve serialized to/from just streams, rather than getting a StreamWriter involved. It’s simpler to let the XML infrastructure deal with all the encoding.

    The above code works fine for me in a simple test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I have provided the EXACT source code I'm using to try to figure
I am using Komodo Edit , a code editor. When I right click on
I've been using Komodo Edit for a small project in Django. The code completion
Using the following code: Function GetSetting(Of T)(ByVal SettingName As String, ByRef DefaultVal As T)
Authorize.net provides some sample code for using CIM with ruby but its uses XML.
I'm currently developing an application and I'm using this post code to get the
I'm using code provided in this answer to create a dynamic label and it
I'm rendering a prototype using below code: {{form_widget(form.get('prototype').myField, {'attr': {'value': '<%= myModelProperty %>'} })
In my project I am using Reachability class provided by Apple. When there is
I am using a code example block in an XML comment as a simple

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.