none
Need help with binary RRS feed

  • Question

  • Hello,

    I am creating a program that saves info to an xml.

    I want to create a binary file from the xml data.

    But I only want to read the opening nodes, not the closed one's.

    and only the inner text of the attributes 

    Here is a sample to work with :

    <?xml version="1.0" encoding="utf-16"?>
    <File Version="1.0" AppVersion="1.0.0.0">
      <Parent>
        <Eldest_Child>
          <Grand_Child_One>
            <Info Name="Grand_Child_One_Name">John Doe</Info>
    	  </Grand_Child_One>
    	</Eldest_Child>
      </Parent>
    <File>

    I want to use BinaryReader to read through the xml 

    and then use BinaryWriter to save everything except 

    the opening nodes  and the inner text 

    leave the opening nodes  and the inner text, binary everything else .

    Example :

      Parent
         Eldest_Child
            Grand_Child_One
                                 Grand_Child_One_Name
       

    Any help with methods would be great

    Regards


    • Edited by Joe Essex Monday, February 18, 2019 2:57 AM
    Monday, February 18, 2019 2:39 AM

All replies

  • Hi Joe Essex

    Thank you for posting here.

    For your question, you want to create a binary file from the xml data.

    >>I want to use BinaryReader to read through the xml.

    I suggest that it is best for you to read xml by using XmlDocument or XElement.

    You could try the following code to get it.

    static void Main(string[] args)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(@"C \first.xml");
                XmlElement element = xmlDocument.DocumentElement;
                XmlNode xn = xmlDocument.SelectSingleNode("/File/Parent");
                XmlNode xn1 = xmlDocument.SelectSingleNode("/File/Parent/Eldest_Child");
                XmlNode xn2 = xmlDocument.SelectSingleNode("/File/Parent/Eldest_Child/Grand_Child_One");
                XmlNode xn3 = xmlDocument.SelectSingleNode("/File/Parent/Eldest_Child/Grand_Child_One/Info");
                Console.WriteLine(xn.Name);
                Console.WriteLine(xn1.Name);
                Console.WriteLine(xn2.Name);
                Console.WriteLine(xn3.Attributes["Name"].Value);
                string total = xn.Name +Environment.NewLine+ xn1.Name + Environment.NewLine + xn2.Name +Environment.NewLine + xn3.Attributes["Name"].Value;
                string fileName= @"C \AppSettings.bin";
                using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
                {
                    writer.Write(1.250F);
                    writer.Write(total);
                    writer.Write(10);
                    writer.Write(true);
                }
                Console.WriteLine("success");
                Console.ReadKey();
    
            }
    

    Result:

    Hope my solution could be helpful.

    Best regards,

    Jack



    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.

    Monday, February 18, 2019 8:54 AM
    Moderator
  • Hi Jack,

    Thank you, but that's not exactly what I'm looking for.

    I want to create a Default.dicx file for my programs.

    If you could take a look at the projects, you can prolly

    figure out how to make the proper methods needed to do it.

    Here is a link to them :

    LanguageEditor and DicxFiler Projects

    Regards 

    Monday, February 18, 2019 11:48 PM
  • Hi Joe Essex

    Thanks for the feedback.

    According to your description, you could try the following change in my last reply code.

    Change:

               
     string fileName= @"C :\AppSettings.bin";

    into

     string fileName= @"C : \Default.dicx";


    Best regards,

    Jack


    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 6:49 AM
    Moderator
  • Hi Joe,

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer , so that it will help other members to find solution quickly if they faces similar issue. If not, please feel free to let me know.

    Best Regards,

    Jack


    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.

    Thursday, February 21, 2019 6:50 AM
    Moderator