none
Can I get some help to write an xml to binary RRS feed

  • Question

  • hello,

    I am trying to create a binary dictionary file for a program.

    The settings file is in xml, and I want the program to load the binary file.

    here is the code of the xml:

    <?xml version="1.0" encoding="utf-16"?>
    <Lang Version="1.0" AppVersion="1.0.0.0">
      <Dialogs>
        <Main>
          <Menus>
            <I Name="Main_Menu_Load">Load</I>
            <I Name="Main_Menu_Save">Save</I>
            <I Name="Main_Menu_Exit">Exit</I>
            <I Name="Main_Menu_SaveAll">Save All</I>
            <I Name="Main_Menu_Close">Close</I>
            <I Name="Main_Menu_CloseAll">Close All</I>
            <I Name="Main_Menu_Languages">Languages</I>
            <I Name="Main_Menu_Help">Help</I>
            <I Name="Main_Menu_Help_About">About</I>
            <I Name="Main_Menu_Help_CheckForNewVersion">Check For New Version</I>
            <I Name="Main_Text_LoadLanguage">Load Language {0}</I>
            <I Name="Main_Menu_LoadMultiple">Load Multiple</I>
            <I Name="Main_Menu_EmptyTextsColor">Empty Texts Color</I>
            <I Name="Main_Menu_MatchingTextsColor">Matching Texts Color</I>
            <I Name="Main_Menu_ExpandAll">Expand All</I>
            <I Name="Main_Menu_CollapseAll">Collapse All</I>
            <I Name="Main_Menu_ChangeColors">Change Colors</I>
          </Menus>
          <Headers>
            <I Name="Main_HDR_Name">Name</I>
            <I Name="Main_HDR_WarningName">Name</I>
            <I Name="Main_HDR_WarningLanguages">Languages</I>
            <I Name="Main_HDR_ErrorName">Name</I>
            <I Name="Main_HDR_ErrorLanguage">Language</I>
          </Headers>
          <Texts>
            <Logs>
              <I Name="Main_Text_MissingFormatArgument">Missing format arguments : {0}</I>
            </Logs>
            <I Name="Main_Text_Warnings">{0} Warnings</I>
            <I Name="Main_Text_Errors">{0} Errors</I>
          </Texts>
        </Main>
      </Dialogs>
      <Questions>
        <I Name="Question_SaveChangesToFollowingLangs">Save changes to the following language(s) ?</I>
      </Questions>
      <Infos>
        <I Name="Info_XmlSavedTo">'{0}' xml saved to {1}</I>
        <I Name="Info_DicxSavedTo">'{0}' dicx saved to {1}</I>
        <I Name="Info_LanguageAlreadyLoadedAt">'{0}' already loaded at {1}</I>
      </Infos>
      <Errors>
        <I Name="Error_LanguageItemsAreMissing">{0} language item(s) are missing in {1}</I>
      </Errors>
      <XSystem.Update>
        <Dialogs>
          <I Name="Info_UpdateAvailable">Version : {0} is available</I>
          <I Name="Info_CheckingForNewVersion">Checking for new version</I>
        </Dialogs>
      </XSystem.Update>
    </Lang>

    What I need is binarywrite code to save this to a binary file

    Here is a link to my project:

    LanguageEditor and DicxFiler download

    any help would be great

    Thank you



    • Edited by dxe2dsf Friday, February 15, 2019 6:23 PM
    Wednesday, February 13, 2019 8:29 PM

All replies

  • Hi dxe2dsf,

    Could you explain what "a binary dictionary file" is? How does it work?

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Thursday, February 14, 2019 12:46 AM
  • Hi dxe2dsf,

    Thank you. But machine translation doesn't always help my understanding.
    Please use English.

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Thursday, February 14, 2019 2:25 AM
  • Hi Ashidacchi, 

    A "binary dictionary file "

    Is a file in the language that the programs I create,

    loads to display the text of all the components of the program.

    And stores them in the XML file.

    The user can only change the internal text of the node,

    but not the name of the node.

    Also, users cannot add items to an XML file,

    because they won't be loaded into the program.

    This is because everything in the xml is converted to the  "binary dictionary file " .

    Then users can choose the language they want, such as:

    English, German, Russian, Greek, Chinese, Japanese

    ect.  

    Thank you,

    I hope this will help you


    Thursday, February 14, 2019 6:14 PM
  • Hi dxe2dsf,

    Firstly, thank you for explanation about A "binary dictionary file".

    Secondly, sorry I don't have enough skill to read/write C# for providing a solution.  I've downloaded your shared projects and just found them using C#.

    I'd like to ask one question for the future.  Do you want to make your application(s) multi-lingual?

    Regards,



    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Friday, February 15, 2019 12:36 AM
  • Hi  Ashidacchi,

    Yes, that's what I already did.

    The reason for the binary dictionary file, is so users can't

    modify the language.xml. 

    Hence:

    "English, German, Russian, Greek, Chinese, Japanese "

    If you loaded the project in Visual Studio, you can see on the menu strip

    under File, the save dicx file ToolStripItem. It will not be visible on the published version.

    It is for my developing purpose only. however, experienced programmers can decompile it

    with .net register or Teleriks just decompile. If they want to add features to the program.

    Regards,



    • Edited by dxe2dsf Friday, February 15, 2019 2:19 AM
    Friday, February 15, 2019 2:09 AM

  • <?xml version="1.0" encoding="utf-16"?>
    <Lang Version="1.0" AppVersion="1.0.0.0">
      <Dialogs>
        <Main>
          <Menus>
            <I Name="Main_Menu_Load">Load</I>
            <I Name="Main_Menu_Save">Save</I>
            <I Name="Main_Menu_Exit">Exit</I>
            <I Name="Main_Menu_SaveAll">Save All</I>
            <I Name="Main_Menu_Close">Close</I>
            <I Name="Main_Menu_CloseAll">Close All</I>
            <I Name="Main_Menu_Languages">Languages</I>
            <I Name="Main_Menu_Help">Help</I>
            <I Name="Main_Menu_Help_About">About</I>
            <I Name="Main_Menu_Help_CheckForNewVersion">Check For New Version</I>
            <I Name="Main_Text_LoadLanguage">Load Language {0}</I>
            <I Name="Main_Menu_LoadMultiple">Load Multiple</I>
            <I Name="Main_Menu_EmptyTextsColor">Empty Texts Color</I>
            <I Name="Main_Menu_MatchingTextsColor">Matching Texts Color</I>
            <I Name="Main_Menu_ExpandAll">Expand All</I>
            <I Name="Main_Menu_CollapseAll">Collapse All</I>
            <I Name="Main_Menu_ChangeColors">Change Colors</I>
          </Menus>
          <Headers>
            <I Name="Main_HDR_Name">Name</I>
            <I Name="Main_HDR_WarningName">Name</I>
            <I Name="Main_HDR_WarningLanguages">Languages</I>
            <I Name="Main_HDR_ErrorName">Name</I>
            <I Name="Main_HDR_ErrorLanguage">Language</I>
          </Headers>
          <Texts>
            <Logs>
              <I Name="Main_Text_MissingFormatArgument">Missing format arguments : {0}</I>
            </Logs>
            <I Name="Main_Text_Warnings">{0} Warnings</I>
            <I Name="Main_Text_Errors">{0} Errors</I>
          </Texts>
        </Main>
      </Dialogs>
      <Questions>
        <I Name="Question_SaveChangesToFollowingLangs">Save changes to the following language(s) ?</I>
      </Questions>
      <Infos>
        <I Name="Info_XmlSavedTo">'{0}' xml saved to {1}</I>
        <I Name="Info_DicxSavedTo">'{0}' dicx saved to {1}</I>
        <I Name="Info_LanguageAlreadyLoadedAt">'{0}' already loaded at {1}</I>
      </Infos>
      <Errors>
        <I Name="Error_LanguageItemsAreMissing">{0} language item(s) are missing in {1}</I>
      </Errors>
      <XSystem.Update>
        <Dialogs>
          <I Name="Info_UpdateAvailable">Version : {0} is available</I>
          <I Name="Info_CheckingForNewVersion">Checking for new version</I>
        </Dialogs>
      </XSystem.Update>
    </Lang>

    I sure hope someone is looking through the Apps, to help me figure out how to write

    the methods for creating a Default.dicx from a LangguageFile - English.xml.

    I have been working on it, but to no avail.

    Thanks to everyone in advance

    for any help given.

    Regards


    Sunday, February 17, 2019 2:55 AM
  • Hi dxe2dsf,

    I have download your source file. But I still do not understand what you want.

    The LangguageFile.cs of DicxFiler is used to create a xml node. There is no code for creating .dicx file.

    Based on my search, I do not find the library to create .dicx file using C#.

    Could you provide more details about what you want?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 19, 2019 8:04 AM
    Moderator
  • Hello Wendy,

    There is code in the DicxFiler To create a default,dicx.

    I just can't figure out how to create the methods needed to it.

    Take a look at the dicfile.cs in the dicxfiler dll.

    the is a method "CreateFtomLanguageFile"

    using System;
    using System.Collections.Generic;
    using System.IO;
    using XSystem.Core;
    
    namespace DicxFiler
    {
        public class DicFile
        {
            public const string DefaultFileName = "Default.dicx";
    
            public Dictionary<string, DicItem> AllItems = new Dictionary<string, DicItem>(StringComparer.OrdinalIgnoreCase);
    
            public DicCollection Items;
    
            public static DicFile CreateFromLanguageFile(LanguageFile file)
            {
                DicFile dicFile = new DicFile()
                {
                    Items = new DicCollection(null, file)
                };
                DicFile.CreateItems(dicFile.Items, dicFile, file.Items);
                return dicFile;
            }
    
            private static void CreateItems(DicCollection dicCollection, DicFile dicFile, LanguageNodesCollection collection)
            {
                foreach (string key in collection.Keys)
                {
                    string name = collection[key].Name;
                    if (!(collection[key] is LanguageNodesCollection item))
                    {
                        LanguageNode languageNode = (LanguageNode)collection[key];
                        DicItem dicItem = new DicItem(dicCollection, dicFile)
                        {
                            Name = name,
                            FormatArgumentsCount = Utils.CountFormatArguments(languageNode.Text)
                        };
                        dicCollection[name] = dicItem;
                    }
                    else
                    {
                        DicCollection dicCollection1 = new DicCollection(dicCollection, dicFile)
                        {
                            Name = name
                        };
                        dicCollection[name] = dicCollection1;
                        DicFile.CreateItems(dicCollection1, dicFile, item);
                    }
                }
            }
    
            public bool Open(string filePath)
            {
                bool flag;
                if (File.Exists(filePath))
                {
                    this.AllItems.Clear();
                    BinaryReader binaryReader = new BinaryReader(File.OpenRead(filePath));
                    try
                    {
                        this.Items = new DicCollection(binaryReader, null, this);
                    }
                    finally
                    {
                        binaryReader.Close();
                    }
                    flag = true;
                }
                else
                {
                    CoreTools.ShowError("Could not find dicx file");
                    flag = false;
                }
                return flag;
            }
    
            public bool OpenDefault(string dirPath)
            {
                bool flag = this.Open(Path.Combine(dirPath, "Default.dicx"));
                return flag;
            }
    
            public void Save(string filePath)
            {
                BinaryWriter binaryWriter = new BinaryWriter(File.Create(filePath));
                try
                {
                    DicFile.Write(binaryWriter, this.Items);
                }
                finally
                {
                    binaryWriter.Close();
                }
            }
    
            public static void Write(BinaryWriter bw, DicCollection collection)
            {
                bw.Write(collection.Count);
                bw.Write(collection.Name);
                foreach (IDicItem value in collection.Values)
                {
                    if (!(value is DicCollection dicCollection))
                    {
                        bw.Write(false);
                        DicItem dicItem = (DicItem)value;
                        bw.Write(dicItem.Name);
                        bw.Write(dicItem.FormatArgumentsCount);
                    }
                    else
                    {
                        bw.Write(true);
                        DicFile.Write(bw, dicCollection);
                    }
                }
            }
        }
    }


    What I'm thinking is that it should collect the items of the xml

    file and then save the default.dicx file.

    Here is what I have been trying to create :

    private void SaveDicxFileToolStripMenuItem_Click(object sender, EventArgs e)
    {
    	SaveFileDialog sfd = new SaveFileDialog()
    	{
    		InitialDirectory = this.path,
    		Filter = "DICX Files(*.dicx)|*.dicx|All Files (*.*)|*.*",
    		FilterIndex = 1,
    		RestoreDirectory = true
    	};
    	if (sfd.ShowDialog() == DialogResult.OK)
    	{
    		 string dfile = sfd.FileName;
    		 string Dfile = path + "/English.xml";
    		 DicxFiler.LanguageFile dicxfile = new DicxFiler.LanguageFile(Dfile);
    		 DicxFiler.DicFile.CreateFromLanguageFile(dicxfile).Save(dfile);
    	}
    }
    

    It doesn't work, I know I am creating it wrong.

    I hope this will help you see what I mean.

    regards 


    • Edited by dxe2dsf Tuesday, February 19, 2019 10:20 AM
    Tuesday, February 19, 2019 10:04 AM
  • Hi dxe2dsf,

    Thank you for feedback.

    I test the code. But I do not find the .dicx file extension. How do you use it? Based on my search, I do not find any information of this file extension online as well.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 20, 2019 5:39 AM
    Moderator
  • Hello Wendy,

    I'm Working on trying to get it done. The dicx file extension is original

    so you won't fine any info on it online. I'm trying to get other experienced

    programmers to help me, by  working with the project. Because as you

    know, two heads are better then one.

    For new viewer's : 

    "The link to download the projects on the first post"

    Regards'


    • Edited by dxe2dsf Thursday, February 21, 2019 4:51 PM
    Thursday, February 21, 2019 4:39 PM
  • Hello, 

    You doing a bit unreasonable job - you already have your dictionary stored in an external file. In XML format.
    To use it inside your application as a Dictionary<string, DicItem> you need just load your XML file as XmlDocument ( or open as an XmlReader) and transform loaded document into dictionary. 

    If you need to edit and store your dictionary - you need to do opposite - convert dictionary into proper XmlDocument and save document.

    As far as I can see - you can't directly serialize your dictionary into Xml file - it will have different format. Implementation of "binary save" would not give much benefit in terms of productivity, but create a lot of misunderstand and problem. 

    -----

    You also may need to read about resources and localization instead of inventing another pushbike.


    Sincerely, Highly skilled coding monkey.

    Thursday, February 21, 2019 4:58 PM
  • >I need to be able to save the loaded xml to the binary dicx file.

    Are you planing to load your dicx-file again? You already have one mechanism for loading - you load an xml file. this task is done. Why you try to get a second mechanism? I do not see any benefits on having the same data in two incompatible format.

    If you insist to serialize/deserialize dictionary object - read this:

    https://stackoverflow.com/questions/36333567/saving-a-dictionaryint-object-in-c-sharp-serialization


    Sincerely, Highly skilled coding monkey.

    Monday, February 25, 2019 9:07 AM
  • Forget it
    Monday, February 25, 2019 10:58 PM