mortb wrote:
My users shall be able to upload xml documents to my web server.
I will check the validity of the documents with my xsd schema.
The document will contain something like:
<project>
<project-item />
</project>
1- How do they specify in the xml document that they are using my schema
with no namespace prefix?
2- When checking the validity, how do I make sure that they have specified
my schema in their document?
3- If they haven't specified my schema in their xml, how do I tell the
XmlReader that my schema shall be used on the namespace with no prefix?
With .NET 2.0 to do validation you use e.g.
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.Schemas.Add(null, "schema.xsd");
readerSettings.ValidationEventHandler += new
ValidationEventHandler(YourHandler);
using (XmlReader xmlReader = XmlReader.Create(@"file.xml",
readerSettings)
{
// now pull in node and check events in your
// ValidationEventHandler
while (xmlReader.Read()) {}
}
If you want the reader to use the
schemaLocation/noNamespaceSchemaLocation attribute(s) then you do not
need to add the schema yourself, rather you need to set a validation
flag to use schema location attributes.
If you want to first check whether the document refers to your schema
then you might want to start reading it and look at validation warnings
whether a schema has been found.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/