473,326 Members | 2,255 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,326 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 4445


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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.