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

  • SEARCH
  • Home
  • 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 7942545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:00:15+00:00 2026-06-04T00:00:15+00:00

I have this XML file <bookstore> <test> <test2/> </test> </bookstore> and this XSD schema

  • 0

I have this XML file

<bookstore>  
  <test>
    <test2/>
  </test>
</bookstore>

and this XSD schema

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="bookstore" type="bookstoreType"/>     
  <xsd:complexType name="bookstoreType">
    <xsd:sequence maxOccurs="unbounded">  
      <xsd:element name="test" type="xsd:anyType" />
    </xsd:sequence>                                       
  </xsd:complexType>
</xsd:schema>

I intend to validate xml file from C# code.
There is a method that validate XML file:

    // validate xml
    private void ValidateXml()
    {
        _isValid = true;

        // Get namespace from xml file
        var defaultNamespace = XDocument.Load(XmlFileName).Root.GetDefaultNamespace().NamespaceName;

        // Set the validation settings.
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.ValidationType = ValidationType.Schema;
        settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
        settings.Schemas.Add(defaultNamespace, XsdFileName);
        settings.ValidationEventHandler += OnValidationEventHandler;

        // Create the XmlReader object.
        using(XmlReader reader = XmlReader.Create(XmlFileName, settings))
        {
            // Parse the file. 
            while (reader.Read()) ;    
        }
    }

    private void OnValidationEventHandler(object s, ValidationEventArgs e)
    {
        if (_isValid) _isValid = false;

        if (e.Severity == XmlSeverityType.Warning)
            MessageBox.Show("Warning: " + e.Message);
        else
            MessageBox.Show("Validation Error: " + e.Message);
    }

I know, this XML file is valid. But my code reterns this Error:

Validation Error: Could not find schema information for the element 'test2'

Where is my mistake?

Thanks!!!

  • 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-06-04T00:00:18+00:00Added an answer on June 4, 2026 at 12:00 am

    UPDATE: I assume your code matches the error you listed (I’ve tried your code on .NET 3.5SP1, and I wasn’t able to reproduce your behaviour). The workaround below should work for sure (the error you’re getting is consistent to a process contents clause strict as opposed to lax).

    Replace <xsd:element name="test" type="xsd:anyType" /> with a complex content that allows for xsd:any, like this:

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
        <xsd:element name="bookstore" type="bookstoreType"/> 
        <xsd:complexType name="bookstoreType"> 
            <xsd:sequence maxOccurs="unbounded"> 
                <xsd:element name="test">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence> 
        </xsd:complexType> 
    </xsd:schema> 
    

    Having “lax” will still yield a message; you could use “skip” if you want that message gone. Regardless, skip and lax in an xsd:any gives you what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
I have this xml file: Response: <ns3:ExecuteResponse xmlns:ns3=http://www.opengis.net/wps/1.0.0 xmlns:ns1=net/ows/1.1 xmlns:ns2=http://www.w3.org/1999/xlink statusLocation=xxxxf62 serviceInstance=http:/http-post version=1.0.0 service=xxx>
I have this XML file: <movie id = 0> <Movie_name>The Shawshank Redemption </Movie_name> <Address>http://www.imdb.com/title/tt0111161/
I have this xml-file: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#444548"> <ImageView android:layout_width="wrap_content"
I have this XML file: http://www.basket.ba/ksbih/xml/200_07.xml I've used all the major functions and classes
I have this inside my spring xml file: <object type=Test.Web.Utilities.TestClass, Test.Web singleton=false id=TestClass> <property
I have this test code that just saves an XML file to a folder.
I have this xml file. The list contains 2 items. When I test the
I have this xml-file: <objects> <object> <value>test</value> </object> <object> <value>foo</value> </object> <object> <value>bar</value> </object>

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.