Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Have a problem in C# while trying to know if an xml file is valid or not according to its schema in an xsd file

$
0
0

Hello. I have a problem while trying to know if an xml file is valid or not according to its schema in a xsd file.

It gives me an error that is in my xsd file.

It says "Wildcard '##any' allows element 'http://www.irica.com/ECEP/1383-12/SendSchema:Attachments', and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence."

Here is my code :

try
            {
                XmlReaderSettings Xsettings = new XmlReaderSettings();
                Xsettings.ValidationType = ValidationType.Schema;

                openFileDialog1.Title = "The address of the xsd file";
                openFileDialog1.Filter = "xsd files|*.xsd";
                openFileDialog1.ShowDialog();
                if (openFileDialog1.FileName == "")
                {
                    MessageBox.Show("Operation was cancelled.");
                }
                else
                {
                    Xsettings.Schemas.Add(null, openFileDialog1.FileName);

                    openFileDialog1.FileName = "";
                    openFileDialog1.Title = "The address of the xml file";
                    openFileDialog1.Filter = "xml files|*.xml";
                    openFileDialog1.ShowDialog();

                    if (openFileDialog1.FileName == "")
                    {
                        MessageBox.Show("Operation was cancelled.");
                    }
                    else
                    {
                        XmlDocument document = new XmlDocument();
                        document.Load(openFileDialog1.FileName);

                        XmlReader reader = XmlReader.Create(new StringReader(document.InnerXml), Xsettings);

                        while (reader.Read()) ;
                        MessageBox.Show("Validation was successful.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("The XML file is not valid.\n" + ex.Message);
            }


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>