473,777 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing an XSD file

I'm trying to access a schema file as such:

Dim settings As XmlReaderSettin gs = New
XmlReaderSettin gs()
settings.Schema s.Add(webServic eNamespace, schemaFileName)
settings.Valida tionType = ValidationType. Schema

Even though the webServiceNames pace value above is set to an intranet
address, I keep getting this error:

Could not find file 'C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\X mlCommand.xsd

Why is it looking for the XSD file there? Is there a way to have it
look in the actual spot I put in my code?

Apr 18 '07 #1
12 3028
Doug wrote:
I'm trying to access a schema file as such:

Dim settings As XmlReaderSettin gs = New
XmlReaderSettin gs()
settings.Schema s.Add(webServic eNamespace, schemaFileName)
settings.Valida tionType = ValidationType. Schema

Even though the webServiceNames pace value above is set to an intranet
address, I keep getting this error:

Could not find file 'C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\X mlCommand.xsd

Why is it looking for the XSD file there? Is there a way to have it
look in the actual spot I put in my code?
The second argument to the Add method is the location. The first
argument is simply the namespace URI which is not a location. So pass in
the location as the second argument. For the first argument you can pass
in Nothing, that way the XML parser uses the namespace defined in the
schema.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 18 '07 #2
That worked. But now I'm having a problem with the validate method
that I'm trying to use to validate my xml against my schema. Below is
my code and when it does the xmlDoc.Validate method I get the error:
"The XmlSchemaSet on the document is either null or has no schemas in
it. Provide schema information before calling Validate." Do you know
what might be causing that?

Dim settings As XmlReaderSettin gs = New XmlReaderSettin gs()
settings.Schema s.Add(Nothing, schemaFilePath)
settings.Valida tionType = ValidationType. Schema

Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml( xmlCommandStrin g)

Dim eventHandler As ValidationEvent Handler = New
ValidationEvent Handler(Address Of ValidationEvent Handler)
xmlDoc.Validate (eventHandler)

Apr 18 '07 #3
Doug wrote:
Below is
my code and when it does the xmlDoc.Validate method I get the error:
"The XmlSchemaSet on the document is either null or has no schemas in
it. Provide schema information before calling Validate." Do you know
what might be causing that?

Dim settings As XmlReaderSettin gs = New XmlReaderSettin gs()
settings.Schema s.Add(Nothing, schemaFilePath)
settings.Valida tionType = ValidationType. Schema

Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml( xmlCommandStrin g)
You need to use the above settings when loading the XML e.g. instead of
LoadXml use
xmlDoc.Load(Xml Reader.Create(N ew StringReader(xm lCommandString) ,
settings))

Or as an alternative way, if you only want to validate after loading the
XML, you need to create an XmlSchemaSet and set xmlDoc.Schemas to that
XmlSchemaSet, after you have added your schema(s) to the schema set.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 18 '07 #4
That did the trick. Thank you!

Apr 18 '07 #5
I guess I kind of lied. The code steps through just fine, but the
validation doesn't work. I tried to put some bad xml through this and
it did not do anything to indicate the xml was bad. Here is my final
code if anyone has any idea why it isn't working (I did verify that
the server.mappath function gets me the right result to where my XSD
file is)

Private Function LoadXml(ByVal xmlCommandStrin g As String) As
XmlDocument
Dim settings As XmlReaderSettin gs = New XmlReaderSettin gs()
settings.Schema s.Add(Nothing, Server.MapPath( schemaFileName) )
settings.Valida tionType = ValidationType. Schema

Dim stringRdr As New StringReader(xm lCommandString)
Dim xmlRdr As XmlReader
xmlRdr = XmlReader.Creat e(stringRdr, settings)

Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(xml Rdr)

Dim eventHandler As ValidationEvent Handler = New
ValidationEvent Handler(Address Of ValidationEvent Handler)
xmlDoc.Validate (eventHandler)

Return xmlDoc
End Function

Private Shared Sub ValidationEvent Handler(ByVal sender As Object,
ByVal args As ValidationEvent Args)
Throw New XmlSchemaExcept ion(schemaFileV alidationErrorM essage &
args.Message)
End Sub
Apr 18 '07 #6
Doug wrote:
I guess I kind of lied. The code steps through just fine, but the
validation doesn't work. I tried to put some bad xml through this and
it did not do anything to indicate the xml was bad. Here is my final
code if anyone has any idea why it isn't working (I did verify that
the server.mappath function gets me the right result to where my XSD
file is)
Please post a minimal schema and XML that you are testing, then we can
say more.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 18 '07 #7
This is only a portion of the schema, I haven't tested it with just
this, I tested it with the full version:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XmlCommand " elementFormDefa ult="qualified"
version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://intranet/hstServices/Schemas/XmlCommand.xsd"
xmlns="http://intranet/hstServices/Schemas/XmlCommand.xsd"
xmlns:NS="http://intranet/hstServices/Schemas/XmlCommand.xsd" >
<xs:attribute name="name" type="xs:string " />
<xs:element name="XmlComman d">
<xs:complexType >
<xs:sequence>
<xs:element name="Email" nillable="true" >
<xs:complexType >
<xs:sequence>
<xs:element name="Success">
<xs:complexType >
<xs:sequence>
</xs:sequence>
<xs:attribute name="address" use="optional"
type="xs:string " />
<xs:attribute name="subject" use="optional"
type="xs:string " />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="connectio nKey" use="required"
type="xs:string " />
</xs:complexType>
</xs:element>
</xs:schema>

And here is my xml. I have tried removing the connectionKey value
from the beginning of the xml and it still validates just fine.

<XmlCommand connectionKey=' dbStarrs'>
<Email>
<Success ad************* @ABC.com' subject='Succes sTest'/>
</Email>
</XmlCommand>

Apr 18 '07 #8
Doug wrote:
<xs:schema id="XmlCommand " elementFormDefa ult="qualified"
version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://intranet/hstServices/Schemas/XmlCommand.xsd"
xmlns="http://intranet/hstServices/Schemas/XmlCommand.xsd"
xmlns:NS="http://intranet/hstServices/Schemas/XmlCommand.xsd" >
<xs:attribute name="name" type="xs:string " />
<xs:element name="XmlComman d">
So this schema defines an XmlCommand element in its targetNamespace
which is http://intranet/hstServices/Schemas/XmlCommand.xsd.

Your XML sample however has
<XmlCommand connectionKey=' dbStarrs'>
an XmlCommand element in no namespace. What happens in this case is the
the XML parser looks at the root element, finds it is in no namespace
and then looks for a schema for no namespace. It does not have one
however and that way it simply does lax validation only.

If you set up an XmlReader with a ValidationEvent Handler to report
warnings then you will get a warning that the parser does not find a
schema. However the design of the Validate method you are using is a bit
flawed as it does not allow you to get warnings, it only reports errors.

See also
<http://blogs.msdn.com/xmlteam/archive/2007/04/02/to-trust-or-not-to-trust.aspx>
which recommends "DO TURN ON the ReportValidatio nWarnings flag".
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 19 '07 #9
Hi Martin, so if I understood you correctly part of the issue is that
my sample did not have a targetNamespace within (I think that is what
that blog was talking about too). But, I added this line of code into
my application and it did not even report the warning that the blog
talked about.

settings.Valida tionFlags =
XmlSchemaValida tionFlags.Repor tValidationWarn ings

Is there another way to do this validation then the way I'm doing it?

Apr 19 '07 #10

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

Similar topics

3
2181
by: Paul Phillips | last post by:
Here is what I am trying to do. I have an application that is written in VB 6 and in this application it is accessing a custom dll file that was created using Microsoft Fortran Professional 4.0. Now I have created the same application as far as user interface in a ASP.Net web application but I am having trouble accessing the Fortran dll file. I am doing the DLLImport statement in a class by itself. I make an instance of this class...
23
2909
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the same NT domain, each one has its own web server. The web server is always IIS 5.0.
3
4319
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different geographical locations. I have been completely unsucessful in acheiving this goal so far however. Things I have tried: Create a shortcut to ftp sight via browser then tried to map local drive to
0
2266
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or updating the code-behind dll) accessing any aspx page in the application causes the application to run for the first time. Some of the initialization involves reading and writing some text and xml files using simple streamreader and streamwriter...
5
3068
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet explorer would do in this case. The headers I am getting are: Headers {Content-Disposition: attachment; filename="dynamic_file.mdb" Connection: close Cache-Control: private Content-Type: application/octet-stream
4
3781
by: Khalique | last post by:
I have built a web service whose purpose is to copy files from a secure place to client machine and vice versa. The problem I am having is perhaps related to permissions and access rights. For testing purposes, the secure place is setup on the client machine. The client (window app) calls the web service (on a different machine) and connects successfully to the web service. However, when client calls a method that copies the file from...
3
5006
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function HelloWorld() As > <System.Xml.Serialization.SoapElementAttribute("return")> String
4
3640
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
2
4525
by: Vincent | last post by:
I have been trying to find some API routines that will allow me to determine the name of the computer that is accessing a file on a server. I have found the NetFileEnum call (returns the names of the files in use and the names of the users accessing them). I have also found the NetConnectionEnum call (returns the name of the computer that is accessing a share). I do not see any way of correlating the data that these two api calls...
4
4224
by: Noy B | last post by:
Hi, I have developed a small application that is using a MSAccess DB. the problem is that it was developed on a machine where the application and the DB are both located. now it needs to be change that the application will be able to run on any other machine (using \\ syntax on the run command- not a problem) using the DB located on a static-different machine. for this purpose I need to create a Remote Connection from my
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.