471,582 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 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 4267


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by maddalimurali | last post: by
1 post views Thread by Mark Olbert | last post: by
6 posts views Thread by Iain | last post: by
3 posts views Thread by Shailendra Batham | last post: by
7 posts views Thread by =?Utf-8?B?Q29kZVJhem9y?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

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.