I managesd to compile in VS 2003 command-line utility - by running xsd from
within the directory where xsd files are.
Still cannot compile schema in code - it errors with "Cannot resolve
schemaLocation attribute" message.
I use the following code to add schema to XmlValidatingReader:
using System.IO;
using System.Xml;
using System.Xml.Schema;
....
string schemaFielName = this.Server.MapPath("~/schemas/Inc_B.xsd");
XmlSchema sch = XmlSchema.Read(new StreamReader(schemaFielName), new
ValidationEventHandler(this.validateSchema));
sch.Compile(new ValidationEventHandler(this.validateSchema), new
XmlUrlResolver));
if (sch.IsCompiled)
{
XmlValidatingReader reader = new XmlValidatingReader(new
XmlTextReader(this.Request.Files[0].InputStream));
reader.XmlResolver = new XmlUrlResolver();
reader.Schemas.Add(sch);
reader.ValidationEventHandler += new
ValidationEventHandler(this.validateXml);
while(reader.Read());
}
....
private void validateSchema(object sender, Validation?EventArgs e)
{
Console.Write(e.Message); // I put a breakpoint here
}
What did I do wrong?
I have tried to set up sch.SourceUri to either physical path or Url just
before sch.Compile - same result...
Please HELP!!!
"Sergey Poberezovskiy" wrote:
Zafar,
Yes - they are - I mentioned that in the first sentence..
I may try to explain what I am trying to do:
1. On my website clients need to upload their xml files. Depending on the
client login different schemas should apply.
2. On the server side I need to check whether the file being uploaded is
valid according to my schema (not necessarily the one in the document) - I
add the required schema to the XmlValidationReader.
3. If file passes validation - I can store the info in the database.
The only problem - I cannot COMPILE and hence -validate against added schema
(If I specify that same schema in the document - the document validates just
fine).
"Zafar Abbas" wrote:
Includes and Imports are resolved relative to the current schema document.
Are they present in the same folder as the parent schema?
"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:E4**********************************@microsof t.com... Hi,
I have an .xsd document (Inc_B.xsd) that "includes" two more from the same
folder:
<xs:include schemaLocation="Inc.xsd" />
<xs:include schemaLocation="Inc_A.xsd" />
They all have the same
targetNamespace="http://tempuri.org/Inc.xsd"
xmlns:ir="http://tempuri.org/Inc.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
When I try to use xsd utility from .Net command prompt to compile
Inc_B.xsd - I receive the following error:
Could not find file '\Inc_B folder\Inc.xsd'.
I need to assign 'Inc_B.xsd' as a schema to validate incoming xml files -
but as I cannot compile it - validation fails as Inc_B cannot find type
definitions from the other two files.
Could you please help?
Thanks in advance,
Sergey.