473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Using .xsd files

My message concerns a sample application that I took verbatim from the book
titled "SAMS Teach Yourself Visual Basic.NET Web Programming in 21 days".
It consists of a web page that takes the names of an XML file and
corresponding XML schema (XSD) file as input (via text boxes) and is
supposed to perform a
validation on the XML file. When I run it, I get the following error
message after entering the file names and clicking on the "Validate" button:

Run-time exception thrown : System.Xml.XmlException - The 'xsd:element'
start tag on line '7' doesn't match the end tag of 'xsd:schema' in file
'file:///C:/Inetpub/wwwroot/Practice/simple.xsd'. Line 17, position 3.

Can anyone explain why I get this error?

(I am getting errors also with other sample XML schema-related applications
with this book, so I may have follow-up messages.)

Bob Rosen
Here is the .aspx file that I am executing:

-----------------------------------------------------------

<%@ Page Language="vb" debug="true"%>
<%@ Import Namespace="System.Xml.Schema" %>
<%@ Import Namespace="System.Xml" %>
<HTML>
<script runat="server">
sub CheckXML(Sender as Object, e as EventArgs)

Dim sourceXML as String = Server.MapPath(xmlFileName.Text)
Dim sourceXSD as String = Server.MapPath(xsdFileName.Text)

errorMessage.Text = "Successfully validated " & xmlFileName.Text & _
" using " & xsdFileName.Text
Dim validatingReader as XmlValidatingReader
Dim xmlReader as XmlTextReader
Dim xsdReader as XmlTextReader
Dim testSchemaCollection as new XmlSchemaCollection()
try
xsdReader = new XmlTextReader(sourceXSD)
testSchemaCollection.Add(xsdFileName.Text, xsdReader)
xmlReader = new XmlTextReader(sourceXML)
validatingReader = new XmlValidatingReader(xmlReader)
validatingReader.Schemas.Add(testSchemaCollection)
validatingReader.ValidationType = ValidationType.Schema
AddHandler validatingReader.ValidationEventHandler, _
AddressOf Me.ValidationCallback

while (validatingReader.Read())
end while
catch ex as Exception
errorMessage.Text = "XXX" & ex.ToString()
finally
if not xmlReader is nothing then xmlReader.Close()
if not xsdReader is nothing then xsdReader.Close()
if not validatingReader is nothing then validatingReader.Close()
end try
End Sub

sub ValidationCallback(sender as object, args as ValidationEventArgs)

if args.Severity = XmlSeverityType.Warning then
errorMessage.Text = "Warning: "
end if
if args.Severity = XmlSeverityType.Error then
errorMessage.Text = "Error: "
end if
if not args.Exception is nothing then
errorMessage.Text &= args.Message & " at line " & _
args.Exception.LineNumber & _
" position " & args.Exception.LinePosition & ControlChars.CrLf
end if
End Sub
</script>
<body>
<font face="arial">
<form runat="server">
<h3>XML validation using XSD</h3>
Source XML File:
<asp:TextBox id="xmlFileName" runat="server" /><br>
Source XSD Schema:
<asp:TextBox id="xsdFileName" runat="server" /><br>
<asp:Button Text="Validate" OnClick="CheckXML" runat="server"
id="Button1" />
<br>
<asp:Label id="errorMessage" runat="server" />
</form>
</font>
</body>
</HTML>

-----------------------------------------------------------

Here is the .XML file that I am using as input:

-----------------------------------------------------------

<?xml version="1.0" ?>
<computer xmlns="simple.xsd">
<name>Bob's Computer</name>
<os>Windows XP</os>
<speed>800</speed>
<memory>256</memory>
</Computer>

-----------------------------------------------------------

and here is the .XSD file (simple.xsd) that I am using as input:

-----------------------------------------------------------

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="simple.xsd"
targetNamespace="simple.xsd"
elementFormDefault="qualified">

<xsd:element name="computer">
<xsd:complexType name="computerType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="os" type="xsd:string" />
<xsd:element name="speed" type="xsd:decimal" />
<xsd:element name="memory" type="xsd:decimal" />
</xsd:sequence>
</xsd:complexType>
</xsd:computer>
</xsd:schema>


Jul 19 '05 #1
0 5626

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
3
by: Dan Kjaergaard | last post by:
Hi I created a program using C#, which iterates files and displays these in a listview. However I would like to filter the files, so files won't be displayed if the current user hasn't "read...
1
by: Asha | last post by:
greetings, i need to upload an .xls file using a secure connection. so i though of using https... can i know how this can be done?
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
1
by: ansc1 | last post by:
Hello, I'm new to using php coding. I need help with the following: 1. There is a submit button on the form and is saves information to my database. After clicking on "Save Measurement" it...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: rajasankar | last post by:
Hi, I am using Jython based application and trying to use inspect.py in the python files. Here is my code import inspect,os,sys,pprint,imp def handle_stackframe_without_leak(getframe): ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.