Выскакивает ошибка: В документе XML (1, 2) присутствует ошибка - C#

Узнай цену своей работы

Формулировка задачи:

Возникает ошибка здесь:
object obj = mySerializer.Deserialize(ms);
class Program
{
    static void Main(string[] args)
    {
        using (XmlReader xml = XmlReader.Create("2.xml"))
        {
            while (xml.Read())
            {
                switch (xml.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xml.Name == "entry")
                        {
                            // передаем данные в класс Member
                            Member m = new Member(xml.ReadOuterXml());
                            Console.WriteLine("KUID: {0}", m.ID);
                            Console.WriteLine("Псевдоним: {0}", m.published_datetime);
                           
                            Console.WriteLine("------------------------------------------");
                        }
                        /*else if (xml.Name == "member")
                        {
 
                        }*/
                        break;
                }
            }
        }
        Console.ReadKey();
    }
}
[XmlRoot("entry")]
public class Member
{
    [XmlAttribute("id")]
    public string ID { get; set; }
    [XmlElement("vuln:published-datetime")]
    public string published_datetime { get; set; }
    public Member() { }
 
    public Member(string xml)
    {
        LoadXml(xml);
    }
 
    public void LoadXml(string source)
    {
        XmlSerializer mySerializer = new XmlSerializer(this.GetType());
        using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(source)))
        {
            object obj = mySerializer.Deserialize(ms); // Ошибка здесь
            foreach (PropertyInfo p in obj.GetType().GetProperties())
            {
                PropertyInfo p2 = this.GetType().GetProperty(p.Name);
                if (p2 != null && p2.CanWrite)
                {
                    p2.SetValue(this, p.GetValue(obj, null), null);
                }
            }
        }
    }
}
Не могу понять почему такая ошибка, помогите Пример XML моей:
<?xml version='1.0' encoding='UTF-8'?>
<nvd xmlns:scap-core="http://scap.nist.gov/schema/scap-core/0.1" xmlns:cvss="http://scap.nist.gov/schema/cvss-v2/0.2" xmlns:vuln="http://scap.nist.gov/schema/vulnerability/0.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:patch="http://scap.nist.gov/schema/patch/0.1" xmlns="http://scap.nist.gov/schema/feed/vulnerability/2.0" xmlns:cpe-lang="http://cpe.mitre.org/language/2.0" nvd_xml_version="2.0" pub_date="2015-11-10T03:23:57" xsi:schemaLocation="http://scap.nist.gov/schema/patch/0.1 [url]http://nvd.nist.gov/schema/patch_0.1.xsd[/url] [url]http://scap.nist.gov/schema/feed/vulnerability/2.0[/url] [url]http://nvd.nist.gov/schema/nvd-cve-feed_2.0.xsd[/url] [url]http://scap.nist.gov/schema/scap-core/0.1[/url] http://nvd.nist.gov/schema/scap-core_0.1.xsd">
<entry id="CVE-2014-2406">
    <vuln:vulnerable-configuration id="http://www.nist.gov/">
      <cpe-lang:logical-test operator="OR" negate="false">
        <cpe-lang:fact-ref name="cpe:/a:oracle:database_server:12.1.0.1"/>
        <cpe-lang:fact-ref name="cpe:/a:oracle:database_server:11.2.0.4"/>
        <cpe-lang:fact-ref name="cpe:/a:oracle:database_server:11.2.0.3"/>
        <cpe-lang:fact-ref name="cpe:/a:oracle:database_server:11.1.0.7"/>
      </cpe-lang:logical-test>
    </vuln:vulnerable-configuration>
    <vuln:vulnerable-software-list>
      <vuln:product>cpe:/a:oracle:database_server:11.2.0.4</vuln:product>
      <vuln:product>cpe:/a:oracle:database_server:11.2.0.3</vuln:product>
      <vuln:product>cpe:/a:oracle:database_server:11.1.0.7</vuln:product>
      <vuln:product>cpe:/a:oracle:database_server:12.1.0.1</vuln:product>
    </vuln:vulnerable-software-list>
    <vuln:cve-id>CVE-2014-2406</vuln:cve-id>
    <vuln:published-datetime>2014-04-15T21:55:10.743-04:00</vuln:published-datetime>
    <vuln:last-modified-datetime>2014-04-16T13:22:08.120-04:00</vuln:last-modified-datetime>
    <vuln:cvss>
      <cvss:base_metrics>
        <cvss:score>8.5</cvss:score>
        <cvss:access-vector>NETWORK</cvss:access-vector>
        <cvss:access-complexity>MEDIUM</cvss:access-complexity>
        <cvss:authentication>SINGLE_INSTANCE</cvss:authentication>
        <cvss:confidentiality-impact>COMPLETE</cvss:confidentiality-impact>
        <cvss:integrity-impact>COMPLETE</cvss:integrity-impact>
        <cvss:availability-impact>COMPLETE</cvss:availability-impact>
        <cvss:source>http://nvd.nist.gov</cvss:source>
        <cvss:generated-on-datetime>2014-04-16T13:22:07.870-04:00</cvss:generated-on-datetime>
      </cvss:base_metrics>
    </vuln:cvss>
    <vuln:references xml:lang="en" reference_type="VENDOR_ADVISORY">
      <vuln:source>CONFIRM</vuln:source>
      <vuln:reference href="http://www.oracle.com/technetwork/topics/security/cpuapr2014-1972952.html" xml:lang="en">http://www.oracle.com/technetwork/topics/security/cpuapr2014-1972952.html</vuln:reference>
    </vuln:references>
    <vuln:summary>Unspecified vulnerability in the Core RDBMS component in Oracle Database Server 11.1.0.7, 11.2.0.3, 11.2.0.4, and 12.1.0.1 allows remote authenticated users to affect confidentiality, integrity, and availability via unknown vectors related to "Advisor" and "Select Any Dictionary" privileges.</vuln:summary>
  </entry>
</nvd>

Решение задачи: «Выскакивает ошибка: В документе XML (1, 2) присутствует ошибка»

textual
Листинг программы
using System;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
 
namespace ConsoleApplication5
{
 
    [XmlRoot(Namespace = "http://cpe.mitre.org/language/2.0")]
    public class CpeLangFactRefType
    {
        [XmlAttribute("name")]
        public string Name { get; set; }
    }
 
 
    [XmlRoot(Namespace = "http://cpe.mitre.org/language/2.0")]
    public class CpeLangLogicalTestType
    {
        [XmlAttribute("operator")]
        public string Operator { get; set; }
        
        [XmlAttribute("negate")]
        public string Negate { get; set; }
 
        [XmlElement("fact-ref", typeof(CpeLangFactRefType))]
        public CpeLangFactRefType[] Facts { get; set; }
    }
 
    [XmlRoot(Namespace = "http://cpe.mitre.org/language/2.0")]
    public class VulnVulnerableConfigurationType
    {
        [XmlAttribute("id")]
        public string id { get; set; }
 
        [XmlElement("logical-test", typeof(CpeLangLogicalTestType))]
 
        public CpeLangLogicalTestType LogicalTest { get; set; }
    }
 
 
    [XmlRoot(Namespace = "http://scap.nist.gov/schema/vulnerability/0.4")]
    public class VulnVulnerableSoftwareListType
    {
        [XmlElement("product")]
        public string[] Products { get; set; }
    }
 
    [XmlRoot(Namespace = "http://scap.nist.gov/schema/cvss-v2/0.2")]
    public class CvssBaseMetricsType
    {
        [XmlElement("score")]
        public string Score { get; set; }
 
        [XmlElement("access-vector")]
        public string AccessVector { get; set; }
 
        [XmlElement("access-complexity")]
        public string AccessComplexity { get; set; }
 
        [XmlElement("authentication")]
        public string Authentication { get; set; }
 
        [XmlElement("confidentiality-impact")]
        public string ConfidentialityImpact { get; set; }
 
        [XmlElement("integrity-impact")]
        public string IntegrityImpact { get; set; }
 
        [XmlElement("availability-impact")]
        public string AvailabilityImpact { get; set; }
 
        [XmlElement("source")]
        public string Source { get; set; }
 
        [XmlElement("generated-on-datetime")]
        public DateTime GeneratedOnDateTime { get; set; }
    }
 
    [XmlRoot(Namespace = "http://scap.nist.gov/schema/cvss-v2/0.2")]
    public class VulnCvssType
    {
        [XmlElement("base_metrics", typeof(CvssBaseMetricsType))]
        public CvssBaseMetricsType BaseMetrics { get; set; }
    }
 
    [XmlRoot(Namespace = "http://scap.nist.gov/schema/vulnerability/0.4")]
    public class VulnReferenceType
    {
        [XmlAttribute("href")]
        public string Href { get; set; }
 
        [XmlAttribute("xml:lang")]
        public string XmlLang { get; set; }
    }
 
    [XmlRoot(Namespace = "http://scap.nist.gov/schema/vulnerability/0.4")]
    public class VulnReferencesType
    {
        [XmlAttribute("xml:lang")]
        public string XmlLang { get; set; }
 
        [XmlAttribute("reference_type")]
        public string ReferenceType { get; set; }
 
        [XmlElement("source")]
        public string Source { get; set; }
 
        [XmlElement("reference", typeof(VulnReferenceType))]
        public VulnReferenceType Reference { get; set; }
    }
 
    [XmlRoot(Namespace = "http://scap.nist.gov/schema/vulnerability/0.4")]
    public class EntryType
    {        
        [XmlAttribute("id")]
        public string id { get; set; }
 
        [XmlElement("vulnerable-configuration", typeof(VulnVulnerableConfigurationType))]
        public VulnVulnerableConfigurationType VulnerableConfiguration { get; set; }
 
        [XmlElement("vulnerable-software-list", typeof(VulnVulnerableSoftwareListType))]
        public VulnVulnerableSoftwareListType VulnerableSoftwareList { get; set; }
 
        [XmlElement("cve-id")]
        public string CveId { get; set; }
 
        [XmlElement("published-datetime")]
        public DateTime PublishedDateTime { get; set; }
 
        [XmlElement("last-modified-datetime")]
        public DateTime LastModifiedDateTime { get; set; }
 
        [XmlElement("cvss", typeof(VulnCvssType))]
        public VulnCvssType Cvss { get; set; }
 
        [XmlElement("references", typeof(VulnReferencesType))]
        public VulnReferencesType References { get; set; }
 
        [XmlElement("summary")]
        public string Summary { get; set; }
 
    }
 
    [XmlRoot("nvd", Namespace = "http://scap.nist.gov/schema/feed/vulnerability/2.0")]
    public class Nvd
    {
        public static Nvd Create(string xmlFileName)
        {
            var document = XDocument.Load(xmlFileName);
            var xmlSerializer = new XmlSerializer(typeof(Nvd));
            return (Nvd)xmlSerializer.Deserialize(document.CreateReader());
        }
 
        [XmlAttribute("nvd_xml_version")]
        public double NvdXmlVersion { get; set; }
 
        [XmlAttribute("pub_date")]
        public DateTime PubDate { get; set; }
 
        [XmlElement("entry", typeof(EntryType))]
        public EntryType Entry { get; set; }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            var nvd = Nvd.Create("database.xml");
        }
    }
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4 из 5
Похожие ответы