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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:40:00+00:00 2026-05-15T23:40:00+00:00

I am developing a system that will receive a XML (XmlDocument) via webservice. I

  • 0

I am developing a system that will receive a XML (XmlDocument) via webservice. I won’t have this XML (XmlDocument) on hardisk. It will be managed on memory.

I have a file XSD to validate the XML (XmlDocument) that I receive from my WebService. I am trying to do a example to how validate this Xml.

My XML:

<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

also I have my XSD:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
  <xs:element name="note">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="to" type="xs:string"/>
        <xs:element name="from" type="xs:string"/>
        <xs:element name="heading" type="xs:string"/>
        <xs:element name="body" type="xs:int"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

As we can see, the body field I’ve put as int, just to simulate the error.

Well, to try get the error, I have the following code:

//event handler to manage the errors
private static void verifyErrors(object sender, ValidationEventArgs args)
{
    if (args.Severity == XmlSeverityType.Warning)
        MessageBox.Show(args.Message);
}

On click button, I have:

        private void button1_Click(object sender, EventArgs e)
        {

            try
            {
                // my XmlDocument (in this case I will load from hardisk)
                XmlDocument xml = new XmlDocument();
                // load the XSD schema.. is this right?
                xml.Schemas.Add("http://www.w3schools.com", "meuEsquema.xsd");

                // Load my XML from hardisk
                xml.Load("meusDados.xml");

                // event handler to manage the errors from XmlDocument object
                ValidationEventHandler veh = new ValidationEventHandler(verificaErros);

                // try to validate my XML.. and the event handler verifyError will show the error
                xml.Validate(veh);
            }
            catch {
              // do nothing.. just to test
            }
        }

The problem is that I changed the body field to int, but there are a string value in that field and I am not getting error.

  • 1 1 Answer
  • 1 View
  • 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-15T23:40:00+00:00Added an answer on May 15, 2026 at 11:40 pm

    The problem is XML namespaces.

    In your XSD, you define the targetNamespace= and xmlns= to both be "http://www.w3schools.com":

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               targetNamespace="http://www.w3schools.com"
               xmlns="http://www.w3schools.com"
               elementFormDefault="qualified">
    

    However – your XML document does not contain any XML namespaces.

    <?xml version="1.0"?>
    <note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
    </note>
    

    So basically, that XSD isn’t validating this XML at all.

    You need to either remove those namespaces from your XSD:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               elementFormDefault="qualified">
    

    or alternatively, add the default XML namespace (with no prefix) defined in your XSD to your XML:

    <?xml version="1.0"?>
    <note xmlns="http://www.w3schools.com">
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
    </note>
    

    If you have XML namespaces in your XSD, those have to be present in the XML as well – and vice versa.

    Once you do one or the other solution, you should get a validation error something like:

    Validation error: The 'body' element is invalid - The value 'Don't forget me this weekend!' is invalid according to its datatype
    'http://www.w3.org/2001/XMLSchema:int' - The string 'Don't forget me this weekend!' is not a valid Int32 value.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try pos = document.getElementById('comments').offsetTop May 16, 2026 at 11:49 pm
  • Editorial Team
    Editorial Team added an answer Let a = (x+1)^2, that's 2 ops. Then y=3a +… May 16, 2026 at 11:49 pm
  • Editorial Team
    Editorial Team added an answer Hmm I got the problem: after a little search on… May 16, 2026 at 11:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

We're developing a server system in Scala + Akka for a game that will
We're developing a DDD based system. For a particular module (the publisher) in that
I'm developing some lower end code in my system that uses multiple child classes
I'm developing a system which will be posting messages onto a remote MSMQ queue.
I am developing a system which include a server app & a client app,
We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have
I'm currently developing an IE plugin using SpicIE . This plugin does some web
We have just released a re-written(for the 3rd time) module for our proprietary system.
I'm developing a system using WPF 4. I pretend to use MVC in development.
I'm developing a system with codeigniter, php and jquery these days, still in the

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.