473,378 Members | 1,475 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,378 software developers and data experts.

Validating against a schema without target namespace, is it possib

Ian
I've inherited some xml that doesn't have a namespace and doesn't have a
reference to the schema. The schema doesn't have a targetNamespace attribute.
I'm trying to build a test tool, in C#, which will send the xml to the server
and then validate the response against the schema. When I try and do this I
get a "The attribute targetNamespace does not match the designated namespace
URI" error.

Here's a snippet of the validation code:

XmlParserContext context = new XmlParserContext(null, null, "",
XmlSpace.None);
XmlValidatingReader vr = new XmlValidatingReader(strXmlMessage,
XmlNodeType.Element, context);

XmlSchemaCollection mySchema = new XmlSchemaCollection();
mySchema.Add("urn:sdkgw-schema", "SDKGW.xsd");
vr.ValidationType = ValidationType.Schema;
vr.Schemas.Add(mySchema);
XmlDocument doc = new XmlDocument();
doc.Load(vr);

The first question is can I validate an xml string against a schema that it
doesn't refer to and that doesn't use namespaces? If the answer to that is
yes then can anyone see what I'm doing wrong in my validation code?

thanks, Ian
Jan 12 '06 #1
2 4448


Ian wrote:

The first question is can I validate an xml string against a schema that it
doesn't refer to
Yes, that is certainly possible and even intended to be possible. With
DTDs an XML document is supposed to refer to its DTD and to be checked
against that particular DTD but schemas are meant to be more flexible
and anyone having a schema can check any XML instance document against
that schema.
and that doesn't use namespaces?
If the schema defines elements in no namespace then you can check that
with a validator.
If the answer to that is
yes then can anyone see what I'm doing wrong in my validation code?
Why are you doing
XmlSchemaCollection mySchema = new XmlSchemaCollection();
mySchema.Add("urn:sdkgw-schema", "SDKGW.xsd");


then? If the schema defines elements in no namespace then why are you
passing in a namespace URI as the first argument to the Add method?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 12 '06 #2
Ian


"Martin Honnen" wrote:


Ian wrote:

The first question is can I validate an xml string against a schema that it
doesn't refer to


Yes, that is certainly possible and even intended to be possible. With
DTDs an XML document is supposed to refer to its DTD and to be checked
against that particular DTD but schemas are meant to be more flexible
and anyone having a schema can check any XML instance document against
that schema.
and that doesn't use namespaces?


If the schema defines elements in no namespace then you can check that
with a validator.
If the answer to that is
yes then can anyone see what I'm doing wrong in my validation code?


Why are you doing
> XmlSchemaCollection mySchema = new XmlSchemaCollection();
> mySchema.Add("urn:sdkgw-schema", "SDKGW.xsd");


then? If the schema defines elements in no namespace then why are you
passing in a namespace URI as the first argument to the Add method?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


yes, replacing that namespace with an empty string did the trick.

thank you, Ian
Jan 12 '06 #3

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

Similar topics

2
by: maddalimurali | last post by:
Hello all, My xml and schema file header are as follows. 1) cisGlobals.xsd. <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://www.talgov.com/cisGlobals"...
2
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the...
1
by: Mark Olbert | last post by:
I am trying to validate an XML file that does not contain any xmlns: namespace attribute against a predefined XSD schema. I should think this would be easy to do, since there must be far more...
6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
5
by: Adam Child | last post by:
Hi All, I'm trying to validate an xml document. I'm having trouble setting the default namespace of the xml document. If I hard encode the namespace in the xml file then everything works fine....
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
1
by: Chris Lieb | last post by:
I have an XML Schema file that I know is correct becuase I currently use it in a VB6 program to validate XML documents. Also, if I load an XML file into VS2005 that is not valid against this...
2
by: Mark | last post by:
Hi... I've been trying the .Validate() method on the XmlDocument to validate some xml against a schema, but one thing I noted was that unless the document explicitly declares the schema as a...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
I wrote a method to validate and xml file against a schema. If the file does not conform to the schema, it throws an error. It works fine except for one curious thing. If I try to validate an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.