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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:12:01+00:00 2026-05-26T18:12:01+00:00

I don’t understand why I am getting errors when parsing an xml file. I

  • 0

I don’t understand why I am getting errors when parsing an xml file. I have a class:

class FileSignature
{
    public string signature{ get; set; }
    public string[] extensions{ get; set; }
    public string description { get; set; }
}

I basically need to populate a list of FileSignature List<FileSignature> by parsing an xml file: the xml file looks like:

<?xml version="1.0" encoding="utf-8" ?>

<Files>
  <File>
    <Signature>482B424544562050726F6475637473204C6963656E7365204B65792046696C650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001A</Signature>
    <Extension>KEY</Extension>
    <Description>AviraProductKey</Description>
  </File>
  <File>
    <Signature>FFFE570069006E0064006F0077007300200052006500670069007300740072007900200045006400690074006F0072002000560065007200730069006F006E00200035002E0030003000</Signature>
    <Extension>REG</Extension>
    <Description>RegistryDataFile5.00</Description>
  </File>
  <File>
    <Signature>41565020416E7469766972616C2044617461626173652E202863294B6173706572736B79204C616220313939372D32</Signature>
    <Extension>AVC</Extension>
    <Description>KasperskyAnti-VirusDatabase</Description>
  </File>
  <File>
    <Signature>00000002FFFFFFFFFFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000</Signature>
    <Extension>MAC</Extension>
    <Description>MacPaintBitmapGraphic</Description>
  </File>      
  <File>
    <Signature>52494646????????415649204C495354</Signature>
    <Extension>AVI</Extension>
    <Description>WindowsAudioVideoInterleave</Description>
  </File>      
  <File>
    <Signature>464C5601</Signature>
    <Extension>FLV</Extension>
    <Description>FlashVideo</Description>
  </File>
  <File>
    <Signature>1</Signature>
    <Extension>MPG</Extension>
    <Description>MPEGVideoFile</Description>
  </File>
  <File>
    <Signature>465753</Signature>
    <Extension>SWF</Extension>
    <Description>MacromediaFlashFormat</Description>
  </File>
  <File>
    <Signature>435753</Signature>
    <Extension>SWF</Extension>
    <Description>ShockwaveFlash(v5+)</Description>
  </File>
  <File>
    <Signature>FFD8FF</Signature>
    <Extension>JPG</Extension>
    <Description>JPEG/JIFFImage</Description>
  </File>
  <File>
    <Signature>1F8B08</Signature>
    <Extension>GZ</Extension>
    <Description>GZipCompressedArchive</Description>
  </File>
  <File>
    <Signature>1F9D90</Signature>
    <Extension>Z</Extension>
    <Description>UNIXCompressedArchive</Description>
  </File>
  <File>
    <Signature>494433</Signature>
    <Extension>MP3</Extension>
    <Description>MP3Audio</Description>
  </File>
  <File>
    <Signature>FFFB</Signature>
    <Extension>MP3</Extension>
    <Description>MP3Audio</Description>
  </File>
  <File>
    <Signature>FFFA</Signature>
    <Extension>MP3</Extension>
    <Description>MP3Audio</Description>
  </File>
  <File>
    <Signature>4D5A</Signature>
    <Extension>EXE|COM|DLL|SYS</Extension>
    <Description>WindowsExecutable</Description>
  </File>
  <File>
    <Signature>424D</Signature>
    <Extension>BMP</Extension>
    <Description>WindowsOS/2BitmapGraphics</Description>
  </File>
  <File>
    <Signature>9501</Signature>
    <Extension>SKR</Extension>
    <Description>PGPPrivateKeyring</Description>
  </File>
  <File>
    <Signature>9901</Signature>
    <Extension>PKR</Extension>
    <Description>PGPPublicKeyring</Description>
  </File>

</Files>

and I don’t understand why my code is not working. I don’t want the xml file to be in exact order. In other words I want to treat:

  <File>
    <Signature>4D5A</Signature>
    <Extension>EXE|COM|DLL|SYS</Extension>
    <Description>WindowsExecutable</Description>
  </File>

just like:

 <File>
    <Description>WindowsExecutable</Description>        
    <Extension>EXE|COM|DLL|SYS</Extension>
    <Signature>4D5A</Signature>
  </File>

and my code for parsing that xml file is:

class FileSignature
{
    public string signature;
    public string[] extensions;
    public string description { get; set; }
}

// Constructor here is where I start implementing the algorithm
class FileSignatures
{
    public static List<FileSignature> Files;

    public FileSignatures()
    {
        // list where to place the files
        Files = new List<FileSignature>();


        // that is the path where the xml is located
        XmlTextReader reader = new XmlTextReader(@"A:\Users\Tono\Desktop\SaveContentFromCache\SaveContentFromCache\FileSignatures.xml");


        while (reader.Read())
        {
            // if we find a file element then
            if (reader.Name.ToString().ToLower().Equals("file"))
            {
                // place that entire xml in a string
                string temp = reader.ReadInnerXml().ToString();

                // Create an XmlReader
                XmlReader readerOfParent = XmlReader.Create(new StringReader(temp));

                FileSignature f = new FileSignature();
                while (readerOfParent.Read()) // !!!!!!!!!!!! here is where I get the error 
                {
                    if (readerOfParent.Name.ToString().ToLower().Contains("signature"))
                        f.signature = readerOfParent.ReadInnerXml().ToString();

                    if (readerOfParent.Name.ToString().ToLower().Contains("extension"))
                        f.extensions = readerOfParent.ReadInnerXml().ToString().Split('|');

                    if (readerOfParent.Name.ToString().ToLower().Contains("description"))
                        f.description = readerOfParent.ReadInnerXml().ToString();
                }

                Files.Add(f);
                readerOfParent.Close();


            }

        }
    }

}

EDIT

Reading my algorithm might look confusing. I just need to place the content from the xml file into c#

  • 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-26T18:12:02+00:00Added an answer on May 26, 2026 at 6:12 pm
    XDocument xdoc= XDocument.Load(@"A:\Users\Tono\Desktop\SaveContentFromCache\SaveContentFromCache\FileSignatures.xml");
    
    List<FileSignature> fileSignatures = (from file in xdoc.Element("Files").Elements("File")
             select new FileSignature
             {
               signature= file.Element("Signature").Value,
               extensions= file.Element("Extension").Value.Split('|'),
               description = file.Element("Description").Value
             }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't have much to say, just can get into the event handler. XAML: <Grid>
don't know better title for this, but here's my code. I have class user
Don't ask me how but I'm in a situation where I have DCPs published
Don't ask me why but I need to do the following: string ClassName =
I have just tried to save a simple *.rtf file with some websites and
Don't these two mean the same thing, first get the value and then increment?
Don't ask why but I have the requirement to draw a border around certain
Don't think that I'm mad, I understand how php works! That being said. I
Don't they both have to convert to machine code at some point to execute
Don't overthink this - there's a very commonly used term and I ... have

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.