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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:00:42+00:00 2026-05-17T02:00:42+00:00

I’m trying to validate an XML file with XSD, but I get a Could

  • 0

I’m trying to validate an XML file with XSD, but I get a “Could not find schema information for the element ‘xxx’” for each element and attribute.

My C# code is:

public ReadeXmlFile(string FilePath)
{
    var settings = new XmlReaderSettings
    {
       IgnoreComments = true, 
       ValidationType = ValidationType.Schema,
       CheckCharacters=true,
       ValidationFlags= XmlSchemaValidationFlags.ReportValidationWarnings
    };
    settings.ValidationEventHandler += settings_ValidationEventHandler;
    var xsdReader = new XmlTextReader("KeyEmFileSchema.xsd");
    settings.Schemas.Add(null, xsdReader);

    using (var reader = XmlTextReader.Create(FilePath, settings))
    {
       while (reader.Read()){}
    }
}

void settings_ValidationEventHandler(object sender, ValidationEventArgs e)
{
     Debug.WriteLine(e.Severity + " - " + e.Message);
}

My XML file:

<?xml version="1.0" encoding="utf-16"?>
<keyem description="test"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xsi:noNamespaceSchemaLocation="http://tempuri.org/KeyEmFileSchema.xsd"
>
  <layout type="keyboard" height="300" width="300">
    <groupp text="rad 1">
      <key color="Black" macro="{ESC}10{ESC}43{MOUSERESET}" text="Ordi-\nnarie"/>
      <key color="Gray"  macro="{ESC}10{ESC}B0{MOUSERESET}" text="Släck\nskärm"/>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n1"/>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n2" icon="dfkhfkjsdhfkjdsf">
        <shift color="Blue"  macro="{ESC}1C{ESC}81{MOUSERESET}" text="Annan Skärm"/>
      </key>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n3"/>
      <empty/>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n4"/>
    </groupp>
    <group text="rad 2">
      <key color="Black" macro="{ESC}10{ESC}43{MOUSERESET}" text="Ordi-\nnarie"/>
      <key color="Gray"  macro="{ESC}10{ESC}B0{MOUSERESET}" text="Släck\nskärm"/>
      <group color ="Blue" text="test">
        <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n1"/>
        <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n2"/>
        <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n3"/>
      </group>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n1"/>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n2"/>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n3"/>
      <empty/>
      <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n4"/>
    </group>
  </layout>
</keyem>

My XSD file

<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="FileSchema"
    targetNamespace="http://tempuri.org/KeyEmFileSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/KeyEmFileSchema.xsd"
    xmlns:mstns="http://tempuri.org/KeyEmFileSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:annotation>
    <xs:documentation xml:lang="sv-se">Definition av layout</xs:documentation>
  </xs:annotation>

  <!--Definition av attribut-->
  <xs:attribute name="description" type="xs:string"/>
  <xs:attribute name="text"        type="xs:string"/>
  <xs:attribute name="height"      type="xs:positiveInteger"/>
  <xs:attribute name="width"       type="xs:positiveInteger"/>
  <xs:attribute name="type"        type="LayoutTypeSet" default="keyboard"/>
  <xs:attribute name="macro"       type="xs:string"/>
  <xs:attribute name="icon"        type="xs:base64Binary"/>
  <xs:attribute name="color"       type="ColorType"/>

  <!--Definition av attributgrupp-->
  <xs:attributeGroup name="ShiftKeyAttributeGroup">
    <xs:attribute ref="color" use="optional"/>
    <xs:attribute ref="macro" use="optional"/>
    <xs:attribute ref="text"  use="required"/>
    <xs:attribute ref="icon"  use="optional"/>
  </xs:attributeGroup>

  <!--Definition av root-->
  <xs:element name="keyem">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="layout" type="LayoutType" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
      <xs:attribute ref="description" use="optional"/>
    </xs:complexType>
  </xs:element>

  <!--Definition av komplexa typer-->
  <xs:complexType name="GroupKeyType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="key"   type="KeyType"   minOccurs="0" maxOccurs="unbounded"/>
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="LayoutType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="key"   type="KeyType"   minOccurs="0" maxOccurs="unbounded"/>
    </xs:choice>
    <xs:attribute ref="type"   use="required"/>
    <xs:attribute ref="height" use="optional"/>
    <xs:attribute ref="width"  use="optional"/>
  </xs:complexType>

  <xs:complexType name="GroupType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="key"   type="KeyType"   minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="empty" type="EmptyType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:choice>
    <xs:attribute ref="text"  use="required"/>
    <xs:attribute ref="color" use="optional"/>
  </xs:complexType>

  <xs:complexType name="EmptyType">
    <xs:sequence>
      <xs:element name="empty"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="ShiftType">
    <xs:attributeGroup ref="ShiftKeyAttributeGroup"/>
  </xs:complexType>

  <xs:complexType name="KeyType">
    <xs:sequence>
      <xs:element name="shift" type="ShiftType" minOccurs ="0" maxOccurs="1"/>
    </xs:sequence>
    <xs:attributeGroup ref="ShiftKeyAttributeGroup"/>
  </xs:complexType>


  <!--Definition av enkla typer-->
  <xs:simpleType      name="ColorType">
    <xs:restriction   base="xs:string">
      <!--Regex för att antingen matcha färg angivet på formen #rrggbb eller som är skriven i klarspråk, t.ex. "Green"-->
      <xs:pattern     value="\#[0-9a-fA-F]{6}|[a-zA-Z]+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType      name="LayoutTypeSet">
    <xs:restriction   base="xs:string">
      <xs:enumeration value="keyboard"/>
      <xs:enumeration value="list"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
  • 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-17T02:00:43+00:00Added an answer on May 17, 2026 at 2:00 am

    If you defined schema in the KeyEmFileSchema.xsd file you can use schemaLocation instead of noNamespaceSchemaLocation:

    <keyem description="test"
          xmlns="http://tempuri.org/KeyEmFileSchema.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xsi:schemaLocation="http://tempuri.org/KeyEmFileSchema.xsd KeyEmFileSchema.xsd"
    >
    

    which defines file name (it can be with the path if required) where the definition http://tempuri.org/KeyEmFileSchema.xsd can be found and used. Then you can use

    XmlReaderSettings settings = new XmlReaderSettings ();
    settings.ValidationType = ValidationType.Schema;
    settings.IgnoreWhitespace = true;
    settings.IgnoreComments = true;
    settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation;
    
    XmlReader reader = XmlReader.Create (xmlFilePath, settings);
    

    If you want you can additionally use ValidationEventHandler. Without the handler you will receive exception with the information about validation errors.

    UPDATED: By the way after including of xmlns="http://tempuri.org/KeyEmFileSchema.xsd" and xsi:schemaLocation="http://tempuri.org/KeyEmFileSchema.xsd KeyEmFileSchema.xsd" in the root element of your xml file you will be seen already in Visual Studio Text Editor the errors in your XML file:

    1. Usage of the undeclared attribute description in keyem element.
    2. Usage of all attributes in layout element which are also undeclared.
    3. Usage of groupp element instead of group.

    UPDATED 2: The requirement number 3: to replace groupp to group is clear. Because nobody commented my answer I suppose that somebody ask “what is wrong with attributes of the XML file?”. OK I have to comment this more.

    The problem in your XSD file is that you declare attributes as NOT a part of some simple types, attribute group or attributes of some element. You just declare some “independent” attributes and then use there per “ref” reference. It is in general possible, but this way require usage of qualified attributes. So if you make no changes in your schema the fixed version of your XML file will be following

    <?xml version="1.0" encoding="utf-16"?>
    <keyem xmlns="http://tempuri.org/KeyEmFileSchema.xsd"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xsi:schemaLocation="http://tempuri.org/KeyEmFileSchema.xsd KeyEmFileSchema.xsd"
           a:description="test" xmlns:a="http://tempuri.org/KeyEmFileSchema.xsd"
    >
        <layout a:type="keyboard" a:height="300" a:width="300">
            <group a:text="rad 1">
                <key a:color="Black" a:macro="{ESC}10{ESC}43{MOUSERESET}" a:text="Ordi-\nnarie"/>
                <key a:color="Gray"  a:macro="{ESC}10{ESC}B0{MOUSERESET}" a:text="Släck\nskärm"/>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n1"/>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n2" a:icon="dfkhfkjsdhfkjdsf">
                    <shift a:color="Blue"  a:macro="{ESC}1C{ESC}81{MOUSERESET}" a:text="Annan Skärm"/>
                </key>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n3"/>
                <empty><empty/></empty>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n4"/>
            </group>
            <group a:text="rad 2">
                <key a:color="Black" a:macro="{ESC}10{ESC}43{MOUSERESET}" a:text="Ordi-\nnarie"/>
                <key a:color="Gray"  a:macro="{ESC}10{ESC}B0{MOUSERESET}" a:text="Släck\nskärm"/>
                <group a:color ="Blue" a:text="test">
                    <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n1"/>
                    <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n2"/>
                    <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n3"/>
                </group>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n1"/>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n2"/>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n3"/>
                <empty><empty/></empty>
                <key a:color="Gray"  a:macro="{ESC}1B{ESC}81{MOUSERESET}" a:text="Skärm\n4"/>
            </group>
    
    </layout>
    </keyem>
    

    A small remark: <empty> element is wrong defined in your schema, so to follow the schema we have to use it like <empty><empty/></empty>.

    Another version of possible changes (which you will probably prefer) is to place all attributes in the definition of elements or attribute group. Usage of simple types in your case seems me not needed. So the fixed version of the schema can be following:

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema id="FileSchema"
        targetNamespace="http://tempuri.org/KeyEmFileSchema.xsd"
        elementFormDefault="qualified"
        xmlns="http://tempuri.org/KeyEmFileSchema.xsd"
        xmlns:mstns="http://tempuri.org/KeyEmFileSchema.xsd"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >
      <xs:annotation>
        <xs:documentation xml:lang="sv-se">Definition av layout</xs:documentation>
      </xs:annotation>
    
      <!--Definition av attributgrupp-->
      <xs:attributeGroup name="ShiftKeyAttributeGroup">
        <xs:attribute name="color" type="ColorType"/>
        <xs:attribute name="macro" type="xs:string"/>
        <xs:attribute name="text"  type="xs:string" use="required"/>
        <xs:attribute name="icon"  type="xs:base64Binary"/>
      </xs:attributeGroup>
    
      <!--Definition av root-->
      <xs:element name="keyem">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="layout" type="LayoutType" minOccurs="0" maxOccurs="1"/>
          </xs:sequence>
          <xs:attribute name="description" type="xs:string"/>
        </xs:complexType>
      </xs:element>
    
      <!--Definition av komplexa typer-->
      <xs:complexType name="GroupKeyType">
        <xs:choice maxOccurs="unbounded">
          <xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
          <xs:element name="key"   type="KeyType"   minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
      </xs:complexType>
    
      <xs:complexType name="LayoutType">
        <xs:choice maxOccurs="unbounded">
          <xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
          <xs:element name="key"   type="KeyType"   minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="type"   type="LayoutTypeSet" use="required"/>
        <xs:attribute name="height" type="xs:positiveInteger"/>
        <xs:attribute name="width"  type="xs:positiveInteger"/>
      </xs:complexType>
    
      <xs:complexType name="GroupType">
        <xs:choice maxOccurs="unbounded">
          <xs:element name="group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
          <xs:element name="key"   type="KeyType"   minOccurs="0" maxOccurs="unbounded"/>
          <xs:element name="empty" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="text" type="xs:string" use="required" />
        <xs:attribute name="color" type="ColorType"/>
      </xs:complexType>
    
      <xs:complexType name="ShiftType">
        <xs:attributeGroup ref="ShiftKeyAttributeGroup"/>
      </xs:complexType>
    
      <xs:complexType name="KeyType">
        <xs:sequence>
          <xs:element name="shift" type="ShiftType" minOccurs ="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attributeGroup ref="ShiftKeyAttributeGroup"/>
      </xs:complexType>
    
      <!--Definition av enkla typer-->
      <xs:simpleType      name="ColorType">
        <xs:restriction   base="xs:string">
          <!--Regex för att antingen matcha färg angivet på formen #rrggbb eller som är skriven i klarspråk, t.ex. "Green"-->
          <xs:pattern     value="\#[0-9a-fA-F]{6}|[a-zA-Z]+"/>
        </xs:restriction>
      </xs:simpleType>
    
      <xs:simpleType      name="LayoutTypeSet">
        <xs:restriction   base="xs:string">
          <xs:enumeration value="keyboard"/>
          <xs:enumeration value="list"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:schema>
    

    If we save the new schema in the file KeyEmFileSchema1.xsd then KeyEmFileSchema.xml file can be almost the same as you have before:

    <?xml version="1.0" encoding="utf-16"?>
    <keyem xmlns="http://tempuri.org/KeyEmFileSchema.xsd"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xsi:schemaLocation="http://tempuri.org/KeyEmFileSchema.xsd KeyEmFileSchema1.xsd"
           description="test"
    >
        <layout type="keyboard" height="300" width="300">
            <group text="rad 1">
                <key color="Black" macro="{ESC}10{ESC}43{MOUSERESET}" text="Ordi-\nnarie"/>
                <key color="Gray"  macro="{ESC}10{ESC}B0{MOUSERESET}" text="Släck\nskärm"/>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n1"/>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n2" icon="dfkhfkjsdhfkjdsf">
                    <shift color="Blue"  macro="{ESC}1C{ESC}81{MOUSERESET}" text="Annan Skärm"/>
                </key>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n3"/>
                <empty/>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n4"/>
            </group>
            <group text="rad 2">
                <key color="Black" macro="{ESC}10{ESC}43{MOUSERESET}" text="Ordi-\nnarie"/>
                <key color="Gray"  macro="{ESC}10{ESC}B0{MOUSERESET}" text="Släck\nskärm"/>
                <group color ="Blue" text="test">
                    <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n1"/>
                    <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n2"/>
                    <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n3"/>
                </group>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n1"/>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n2"/>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n3"/>
                <empty/>
                <key color="Gray"  macro="{ESC}1B{ESC}81{MOUSERESET}" text="Skärm\n4"/>
            </group>
    
    </layout>
    </keyem>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.