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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:31:37+00:00 2026-05-20T15:31:37+00:00

The following xml file always seems to validate. Not sure why, but when I

  • 0

The following xml file always seems to validate. Not sure why, but when I remove the following ‘ xmlns=”urn:schemas-microsoft-com:office:spreadsheet” ‘, it seems to throw a validation error as expected.

Somehow MS is preventing validation with the added XSD office schema. So anytime that XSD Schema is included you can’t validate XML using the .NET framework.

Option Strict On
Option Explicit On

Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Imports System.Text

Public Class XMLValidator2

    Private _isValid As Boolean = False

    'Validation Error Count
    Private _ErrorsCount As Integer = 0

    'Validation Error Message
    Private _ErrorMessage As String = ""

    'Declare local objects
    Private _tr As XmlTextReader
    Private _xr As XmlTextReader
    Private _xsc As XmlSchemaSet
    Private _vr As XmlReader

    Public Sub Validate(ByVal strXMLDocPath As String, ByVal strXSDPath As String)

        Try

            _isValid = False
            'Text reader object
            _tr = New XmlTextReader(strXSDPath)
            _xsc = New XmlSchemaSet
            _xsc.Add("", _tr)

            'Validator Object
            Dim settings As New XmlReaderSettings()
            settings.Schemas.Add(_xsc)
            settings.ValidationType = ValidationType.Schema
            'Add validation event handler
            AddHandler settings.ValidationEventHandler, AddressOf Me.ValidationHandler
            _vr = XmlReader.Create(strXMLDocPath, settings)

            _ErrorsCount = 0
            _ErrorMessage = ""

            'Validate XML data
            While (_vr.Read())
            End While
            _vr.Close()
            ' Raise exception, if XML validation fails
            If (_ErrorsCount > 0) Then Throw New Exception(_ErrorMessage)
            'XML Validation succeeded
            _isValid = True

        Catch ex As System.Exception
            'XML Validation failed
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub ValidationHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
        _ErrorMessage = _ErrorMessage + args.Message + "\r\n"
        _ErrorsCount = +1
    End Sub

    Public ReadOnly Property bIsValid() As Boolean
        Get
            Return _isValid
        End Get
    End Property
End Class

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <LastAuthor>KLIMMPI</LastAuthor>
  <Created>2009-06-04T13:49:21Z</Created>
  <LastSaved>2009-06-04T16:10:37Z</LastSaved>
  <Version>11.9999</Version>
 </DocumentProperties>
 <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <Colors>
   <Color>
    <Index>17</Index>
    <RGB>#663399</RGB>
   </Color>
   <Color>
    <Index>39</Index>
    <RGB>#E3E3E3</RGB>
   </Color>
   <Color>
    <Index>45</Index>
    <RGB>#FF3300</RGB>
   </Color>
  </Colors>
 </OfficeDocumentSettings>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>8790</WindowHeight>
  <WindowWidth>30840</WindowWidth>
  <WindowTopX>480</WindowTopX>
  <WindowTopY>90</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s22" ss:Name="Normal_Not 8 Counts">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Arial "/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s24">
   <Font ss:Bold="1"/>
  </Style>
  <Style ss:ID="s25" ss:Parent="s22">
   <Alignment ss:Horizontal="Right" ss:Vertical="Center"/>
   <Borders/>
   <Font ss:FontName="Arial "/>
   <Interior/>
   <NumberFormat/>
  </Style>
  <Style ss:ID="s26" ss:Parent="s22">
   <Alignment ss:Horizontal="Left" ss:Vertical="Center"/>
   <Borders/>
   <Font ss:FontName="Arial "/>
   <Interior/>
   <NumberFormat/>
  </Style>
  <Style ss:ID="s27">
   <Borders/>
   <Font ss:Bold="1"/>
   <Interior/>
  </Style>
  <Style ss:ID="s28">
   <Borders/>
   <Interior/>
  </Style>
  <Style ss:ID="s29">
   <Alignment ss:Horizontal="Right" ss:Vertical="Bottom"/>
   <Borders/>
   <Interior/>
   <NumberFormat ss:Format="@"/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Not 8 Counts">
  <Table ss:ExpandedColumnCount="8" ss:ExpandedRowCount="8" x:FullColumns="1"
   x:FullRows="1">
   <Column ss:AutoFitWidth="0" ss:Width="101.25"/>
   <Column ss:StyleID="s28" ss:AutoFitWidth="0" ss:Width="66.75"/>
   <Column ss:StyleID="s28" ss:AutoFitWidth="0" ss:Width="52.5"/>
   <Column ss:StyleID="s28" ss:AutoFitWidth="0" ss:Width="117.75"/>
   <Column ss:AutoFitWidth="0" ss:Width="62.25"/>
   <Column ss:Index="7" ss:AutoFitWidth="0" ss:Width="68.25"/>
   <Row>
    <Cell ss:StyleID="s24"><Data ss:Type="String">SPAccountIdentifier</Data></Cell>
    <Cell ss:StyleID="s27"><Data ss:Type="String">SPUIAccount</Data></Cell>
    <Cell ss:StyleID="s27"><Data ss:Type="String">SPFein</Data></Cell>
    <Cell ss:StyleID="s27"><Data ss:Type="String">SPLegalName</Data></Cell>
    <Cell ss:StyleID="s24"><Data ss:Type="String">SPRateYear</Data></Cell>
    <Cell ss:Index="7" ss:StyleID="s24"><Data ss:Type="String">Notes</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">1</Data></Cell>
    <Cell><Data ss:Type="Number">204006</Data></Cell>
    <Cell ss:StyleID="s26"><Data ss:Type="String">397221</Data></Cell>
    <Cell ss:StyleID="s26"><Data ss:Type="String">Fake</Data></Cell>
    <Cell><Data ss:Type="Number">2009</Data></Cell>
    <Cell ss:Index="7"><Data ss:Type="String">open subject</Data></Cell>
    <Cell><Data ss:Type="String">Account number dropped proceeding zeros</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">2</Data></Cell>
    <Cell ss:StyleID="s29"><Data ss:Type="String">0018008</Data></Cell>
    <Cell ss:StyleID="s26"><Data ss:Type="String">3905530</Data></Cell>
    <Cell ss:StyleID="s26"><Data ss:Type="String">Fake</Data></Cell>
    <Cell><Data ss:Type="Number">2009</Data></Cell>
    <Cell ss:Index="8"><Data ss:Type="String">account number should be 001008</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">6</Data></Cell>
    <Cell ss:StyleID="s25"><Data ss:Type="String">04045002</Data></Cell>
    <Cell ss:StyleID="s26"><Data ss:Type="String">3915659</Data></Cell>
    <Cell ss:StyleID="s26"><Data ss:Type="String">FAKE</Data></Cell>
    <Cell><Data ss:Type="Number">2009</Data></Cell>
   </Row>
   <Row>
    <Cell ss:Index="2" ss:StyleID="s29"/>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <HorizontalResolution>600</HorizontalResolution>
    <VerticalResolution>600</VerticalResolution>
    <NumberofCopies>0</NumberofCopies>
   </Print>
   <Selected/>
   <Panes>
    <Pane>
     <Number>3</Number>
     <ActiveRow>13</ActiveRow>
     <ActiveCol>3</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Address">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Recipient" type="xs:string" />
        <xs:element name="House" type="xs:string" />
        <xs:element name="Street" type="xs:string" />
        <xs:element name="Town" type="xs:string" />
        <xs:element name="County" type="xs:string" minOccurs="0" />
        <xs:element name="PostCode" type="xs:string" />
        <xs:element name="Country">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="FR" />
              <xs:enumeration value="DE" />
              <xs:enumeration value="ES" />
              <xs:enumeration value="UK" />
              <xs:enumeration value="US" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</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-20T15:31:37+00:00Added an answer on May 20, 2026 at 3:31 pm

    Following worked in my case:

    settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings
    

    Be careful though, it can raise other errors normally ignored.

    ref:
    http://www.dotnetspider.com/resources/2971-Validating-an-XML-File-using-XSD-NET.aspx

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

Sidebar

Related Questions

I have the following XML layout file, HELPME.XML <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have a following XML (part of a .rdl report): <Report xmlns:rd=http://schemas.microsoft.com/SQLServer/reporting/reportdesigner xmlns=http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition> <DataSources>
I'm applying an XSLT stylesheet to the following XML file: <top xmlns=http://www.foo.com/bar> <elementA />
I have the following in an XML file: <entry> ... <link href=http://www.example.com/somelink /> ...
I have JRE 1.6 and am using the following hibernate.cfg.xml file. I am always
I've created a layout.xml file with the following XML, but I can't get the
I have the following xml file: <xfa:data> <form1> <Page1> <Page2> <contractInfo> ... </contractInfo> <paymentInfo>
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I used DataSet to load a schema from following xml file; <node id=0> <node
What is the java programmically equivalent to create the following XML file: <LinearLayout android:layout_width=wrap_content

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.