How to validate an XML Fragment against a Schema using the XMLReader

Posted on 2009-02-22
Last Modified: 2012-05-06
Using the XMLReader, can someone show me an example of validating an XML Fragment against an XML schema? I want to ensure that the value of this field is valid according the schema.  If this can be done, can you please demonstrate.

My Xml fragment that I want to validate.

   <Weights UOM="PG">

Portion of MYSchema.xsd
<xs:element name="Width">
<xs:documentation>5.9.8 (Ref H30)</xs:documentation>
<xs:restriction base="xs:decimal">
<xs:minExclusive value="0"/>
<xs:totalDigits value="8"/>
<xs:fractionDigits value="4"/>
Question by:Hojoformo
    1 Comment
    LVL 9

    Accepted Solution

    Here is EXACTLY how to do it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now