Laden...

XMLReader Validation via DTD fehlerhaft?

Erstellt von KainPlan vor 14 Jahren Letzter Beitrag vor 14 Jahren 1.255 Views
K
KainPlan Themenstarter:in
133 Beiträge seit 2009
vor 14 Jahren
XMLReader Validation via DTD fehlerhaft?

verwendetes Datenbanksystem: XML

Hallo ich hab ein kleines Programm geschrieben das XML Dateien via DTD validieren soll. Nun bekomme ich beim Validieren einer bestimmten Datei einen Validierungsfehler "Das Element 'product' hat ein ungültiges untergeordnetes Element 'illustrations'. Erwartet wurde die Liste möglicher Elemente: 'title .....'". Soweit so gut, aber nach gründlicher Prüfung ist mir aufgefallen das in der DTD ein Element illustrations für das Element product beschrieben ist, auch auf dieser Ebene. Also habe ich mich nach anderen DTD Validatoren umgeschaut und siehe da diese werfen nicht diesen Fehler!

Vermurkst MS da wieder was? Weiß da jemand näheres?

EDIT: hust bin iwie ein bisschen neben der spur heute ^^


    class XmlDTDValidator
    {
        private XmlReader _xmlReader;
        private XmlValidatingReader _xmlValidatingReader;
        private BackgroundWorker _bwValidation;
        private bool _validated;

        /// <summary>
        /// [GET] Path to the XML File.
        /// </summary>
        public string XmlPath { get; private set; }
        /// <summary>
        /// [GET] Status of being Validated.
        /// </summary>
        public bool Validated { get; set; }

        /// <summary>
        /// Create a new instance of this XmlDTDValidator.
        /// </summary>
        /// <param name="xmlPath">Path to the XML-File to validate.</param>
        public XmlDTDValidator(string xmlPath)
        {
            XmlPath = xmlPath;

            _xmlReader = new XmlTextReader(XmlPath);
            _xmlValidatingReader = new XmlValidatingReader(_xmlReader);
            _bwValidation = new BackgroundWorker();
            _bwValidation.DoWork += new DoWorkEventHandler(ValidationWorker);

            _xmlValidatingReader.ValidationType = ValidationType.DTD;
            _xmlValidatingReader.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
        }

        private void ValidationWorker(object sender, DoWorkEventArgs e)
        {
            // Do the Validation.
            _validated = true;
            Validated = false;

            while (!e.Cancel && _xmlValidatingReader.Read())
            {
                // Redirect to the Process Method
                OnNodeProcess(_xmlValidatingReader);
            }
            Validated = _validated;

            OnDone();

            _xmlValidatingReader.Close();
        }

        private void ValidationEventHandler(object sender, ValidationEventArgs e)
        {
            // Redirect to the Process Method
            OnValidation(_xmlValidatingReader, e);            
        }
        /// <summary>
        /// Starts the Validationprocess.
        /// </summary>
        public void Validate()
        {
            _bwValidation.RunWorkerAsync();
        }
        /// <summary>
        /// Delegate for the NodeProcess event.
        /// </summary>
        /// <param name="vr"></param>
        public delegate void NodeProcessEventHandler(XmlValidatingReader vr);
        /// <summary>
        /// Occurs whenever a element is read by the Reader.
        /// </summary>
        public event NodeProcessEventHandler NodeProcess;
        /// <summary>
        /// Occurs whenever a element is read by the Reader.
        /// </summary>
        /// <param name="vr">The Reader.</param>
        protected virtual void OnNodeProcess(XmlValidatingReader vr)
        {
            if (NodeProcess != null)
            {
                Control target = NodeProcess.Target as Control;
                if (target != null && target.InvokeRequired)
                    target.Invoke(NodeProcess, vr);
                else
                    NodeProcess(vr);
            }
        }
        /// <summary>
        /// Occurs whenever the Validation event raise.
        /// </summary>
        public event ValidationEventHandler Validation;
        /// <summary>
        /// Occurs whenever the Validation event raise.
        /// </summary>
        /// <param name="vr">The Reader.</param>
        /// <param name="e">The Arguments.</param>
        protected virtual void OnValidation(XmlValidatingReader vr, ValidationEventArgs e)
        {
            _validated = false;

            if (Validation != null)
            {
                Control target = Validation.Target as Control;
                if (target != null && target.InvokeRequired)
                    target.Invoke(Validation, vr as object, e);
                else
                    Validation(vr as object, e);
            }
        }
        /// <summary>
        /// Occurs whenever the Validationprocess is done.
        /// </summary>
        public event EventHandler Done;
        /// <summary>
        /// Is called whenever the Validationprocess is done.
        /// </summary>
        protected virtual void OnDone()
        {
            if (Done != null)
            {
                Control target = Done.Target as Control;
                if (target != null && target.InvokeRequired)
                    target.Invoke(Done, this, new EventArgs());
                else
                    Done(this, new EventArgs());
            }
        }

K
KainPlan Themenstarter:in
133 Beiträge seit 2009
vor 14 Jahren

Echt niemand eine Ahnung?