471,594 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

validating against schema with namespaces

I have a very complex XDR schema that uses namespaces:

xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:b="urn:schemas-microsoft-com:BizTalkServer"
xmlns:d="urn:schemas-microsoft-com:datatypes"

Do I need to build a custom validator in order to validate XML documents
against this schema? How does the XML parser know how to validate against
the extra namespaces?

For example, schemas-microsoft-com:datatypes allows for attributes such as
maxLength, minLength, etc. If my XML document contains a value that doesn't
meet these criteria, then the document should not be valid. Microsoft's
parser automagically validates correctly, using these custom attributes.

The "schemas-microsoft-com:BizTalkServer" is even more custom, allowing for
such things as a "FieldInfo" element with "format" attributes that specifiy
the exact format for dates and times. I'm pretty sure XmlValidatingReader
doesn't check for these special validations.
If I do have to build my own validator, does anyone have some samples I can
look at? Is there an easy way to do this?

Thanks, Ryan

Nov 12 '05 #1
1 1738
The XmlValidatingReader can validate xml files against XDR schemas. You
should add your XDR schemas to the Schemas property of XmlValidatingReader.
"urn:schemas-microsoft-com:xml-data" and
"urn:schemas-microsoft-com:datatypes" will be understood implicitly but you
need to provide the XDR schema for "urn:schemas-microsoft-com:BizTalkServer"
namespace since it is a custom namespace that the XDR schema parser cannot
understand.

Sample code:
XmlTextReader tr = new XmlTextReader(url);
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.ValidationType = ValidationType.XDR;
vr.Schemas.Add("urn:schemas-microsoft-com:BizTalkServer",
"BiztalkXDRSchema.xdr");
vr.Schemas.Add("myNS","myXdrSchema.xdr");
vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

//Validate
while(vr.Read()) {
}

"Ryan" <no****@nospam.net> wrote in message
news:eZ****************@TK2MSFTNGP09.phx.gbl...
I have a very complex XDR schema that uses namespaces:

xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:b="urn:schemas-microsoft-com:BizTalkServer"
xmlns:d="urn:schemas-microsoft-com:datatypes"

Do I need to build a custom validator in order to validate XML documents
against this schema? How does the XML parser know how to validate against
the extra namespaces?

For example, schemas-microsoft-com:datatypes allows for attributes such as
maxLength, minLength, etc. If my XML document contains a value that doesn't meet these criteria, then the document should not be valid. Microsoft's
parser automagically validates correctly, using these custom attributes.

The "schemas-microsoft-com:BizTalkServer" is even more custom, allowing for such things as a "FieldInfo" element with "format" attributes that specifiy the exact format for dates and times. I'm pretty sure XmlValidatingReader
doesn't check for these special validations.
If I do have to build my own validator, does anyone have some samples I can look at? Is there an easy way to do this?

Thanks, Ryan

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Will | last post: by
6 posts views Thread by Iain | last post: by
1 post views Thread by Christian | last post: by
3 posts views Thread by Shailendra Batham | last post: by
1 post views Thread by Craig Beuker | last post: by
7 posts views Thread by =?Utf-8?B?Q29kZVJhem9y?= | last post: by
reply views Thread by Anwar ali | 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.