Hi all,
I am working on an application that needs to be able to read and lean on the
XMLSchema information contained in the web service description(wsdl).
After i got a wsdl from address : http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx wsdl, I attempt to get its schema and compile using XmlSchema object(iam using vs2003 with .net framework 1.1), but an error occured: "The 'http://www.w3.org/2001/XMLSchema:schema' element is not declared. An error occured at file:///c:\test.xsd(68,9) "
Then I tried to open this schema by Xml Spy, the result shows that this schema is valid. I myselft think that it's ok, but I am confusing why it did not pass the compilation.
+schema:
< xml version="1.0" encoding="utf-8" >
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.cdyne.com/" targetNamespace="http://ws.cdyne.com/" elementFormDefault="qualified">
<element name="GetQuote">
<complexType>
<sequence>
<element name="StockSymbol" type="string" minOccurs="0"/>
<element name="LicenseKey" type="string" minOccurs="0"/>
</sequence>
</complexType>
</element>
<element name="GetQuoteResponse">
<complexType>
<sequence>
<element name="GetQuoteResult" type="tns:QuoteData"/>
</sequence>
</complexType>
</element>
<complexType name="QuoteData">
<sequence>
<element name="StockSymbol" type="string" minOccurs="0"/>
<element name="LastTradeAmount" type="decimal"/>
<element name="LastTradeDateTime" type="dateTime"/>
<element name="StockChange" type="decimal"/>
<element name="OpenAmount" type="decimal"/>
<element name="DayHigh" type="decimal"/>
<element name="DayLow" type="decimal"/>
<element name="StockVolume" type="int"/>
<element name="MktCap" type="string" minOccurs="0"/>
<element name="PrevCls" type="decimal"/>
<element name="ChangePercent" type="string" minOccurs="0"/>
<element name="FiftyTwoWeekRange" type="string" minOccurs="0"/>
<element name="EarnPerShare" type="decimal"/>
<element name="PE" type="decimal"/>
<element name="CompanyName" type="string" minOccurs="0"/>
<element name="QuoteError" type="boolean"/>
</sequence>
</complexType>
<element name="GetQuickQuote">
<complexType>
<sequence>
<element name="StockSymbol" type="string" minOccurs="0"/>
<element name="LicenseKey" type="string" minOccurs="0"/>
</sequence>
</complexType>
</element>
<element name="GetQuickQuoteResponse">
<complexType>
<sequence>
<element name="GetQuickQuoteResult" type="decimal"/>
</sequence>
</complexType>
</element>
<element name="GetQuoteDataSet">
<complexType>
<sequence>
<element name="StockSymbols" type="string" minOccurs="0"/>
<element name="LicenseKey" type="string" minOccurs="0"/>
</sequence>
</complexType>
</element>
<element name="GetQuoteDataSetResponse">
<complexType>
<sequence>
<element name="GetQuoteDataSetResult" minOccurs="0">
<complexType>
<sequence>
<element ref="schema"/>
<any/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
<element name="ImportantMessage">
<complexType/>
</element>
<element name="ImportantMessageResponse">
<complexType>
<sequence>
<element name="ImportantMessageResult" type="string" minOccurs="0"/>
</sequence>
</complexType>
</element>
<element name="QuoteData" type="tns:QuoteData"/>
<element name="decimal" type="decimal"/>
<element name="DataSet" nillable="true">
<complexType>
<sequence>
<element ref="schema"/>
<any/>
</sequence>
</complexType>
</element>
<element name="string" type="string" nillable="true"/>
</schema>
+c# code:
private void Handler(object sender, ValidationEventArgs args)
{
if (args.Severity == XmlSeverityType.Error)
MessageBox.Show ("error : " + args.Message);
}
XmlTextReader tr=new XmlTextReader (@"c:\testnew2.xsd");
XmlSchema schema= XmlSchema.Read (tr, new ValidationEventHandler(Handler) );
schema.Compile(new ValidationEventHandler(Handler) );
Please help me out,
Thanks alot.

Xmlschema compilation problem (.NET framework 1.1)
Dave Abrahams
Hi,
thanks, Did you succesfully compile the collection
Do you think that the problem was caused by System.Xml.Schema of .NET framework 1.1 are you using the 2.0 framework
Even I have added the attribute xmlns:xsd=""... , I was still unable to pass this compilation.
Herbert Wang
Tweak of xsdschema.xsd:
add additional attribute xmlns:xsd="http://www.w3.org/2001/XMLSchema.xsd" to root element.
Now xsdschema.xsd will be valid and it's possible to do collection validation
Psilent Dev
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Yeah, I checked it. (.NET Framework 1.1)
<import namespace="http://www.w3.org/2001/XMLSchema" /> must be used. (see WSDL)
AppzGuy
Thanks for your help, I have tried to do follow your instruction. But the errors still occured : "xsd":string is invalid value for the 'base' attribute. An error occured at the file ///c:/xsdschema.xsd (516,16)."
Otherwise, I have tried to put the include element :<import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation ="http://www.w3.org/2001/XMLSchema.xsd"/> into my testnew2.xsd. It also except errors.
The XML Spy tell me that the "xsdschema.xsd" could not appears to be valid by it self, and being a part of another schema it might still be OK. This message also appears when I modify any valid schema.
This problem still persists.
Help me pls.
Thanks.
Kolle
You are referencing schema of xsd in your schema, i.e. you have to include <import namespace="http://www.w3.org/2001/XMLSchema" /> in the xsd file. Plus, you have to find xsd for xsd. (There is one at "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml\xsdschema.xsd" but it requires tweaking ) and then validate schemas as a collection
XmlSchemaCollection col = new XmlSchemaCollection();
col.ValidationEventHandler += new ValidationEventHandler(Handler);
XmlTextReader trSchema =
new XmlTextReader (@"C:\xsdschema.xsd");
XmlSchema xsdSchema = XmlSchema.Read (trSchema, new ValidationEventHandler(Handler) );
col.Add(xsdSchema);
XmlTextReader tr =
new XmlTextReader (@"C:\testnew2.xsd");
XmlSchema schema= XmlSchema.Read (tr, new ValidationEventHandler(Handler) );
col.Add(schema);
SamLowry
The problem has been absolutely solved.
Somehow, this sounds like very manual and hope that we should never face a analogous problem in the .net 2.0 release.
Thanks again.