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 XmlValidatingRe ader:
using System.IO;
using System.Xml;
using System.Xml.Sche ma;
....
string schemaFielName = this.Server.Map Path("~/schemas/Inc_B.xsd");
XmlSchema sch = XmlSchema.Read( new StreamReader(sc hemaFielName), new
ValidationEvent Handler(this.va lidateSchema));
sch.Compile(new ValidationEvent Handler(this.va lidateSchema), new
XmlUrlResolver) );
if (sch.IsCompiled )
{
XmlValidatingRe ader reader = new XmlValidatingRe ader(new
XmlTextReader(t his.Request.Fil es[0].InputStream));
reader.XmlResol ver = new XmlUrlResolver( );
reader.Schemas. Add(sch);
reader.Validati onEventHandler += new
ValidationEvent Handler(this.va lidateXml);
while(reader.Re ad());
}
....
private void validateSchema( object sender, Validation?Even tArgs 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 XmlValidationRe ader.
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************ *****@discussio ns.microsoft.co m> wrote
in message news:E4******** *************** ***********@mic rosoft.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.