Hi the previous post got messed up, posting again: Dim oSettings As New XmlReaderSettings oSettings.ValidationType = ValidationType.Schema oSettings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema Dim xmlr As XmlReader xmlr = XmlReader.Create(reader, oSettings) Dim myschema1 As XmlSchema = XmlSchema.Read(xmlr, AddressOf ValidationCallback) so far, pretty much textboook code. problem is, it doesnt even begin to validate! I get: "The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'." why is that? here is the XML (it has an inline schema... which is why i set that option in my code) thanks in advance! ---------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xml xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:schema > <xsd:element name="PL_PRICELISTCOUNTRYCUSTOMERTYPENAME"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="71"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="PLDTL_ACDINDICATOR"></xsd:element> <xsd:element name="PL_COUNTRYNAME"> <xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="35"/> </xsd:restriction></xsd:simpleType> </xsd:element> <xsd:element name="ITM_PARTNUMBER"> <xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="16"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="ITM_ITEMNAME"> <xsd:simpleType><xsd:restriction base="xsd:string"><xsd:maxLength value="80"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="pricelist"><xsd:complexType> <xsd:sequence> <xsd:element ref="PL_PRICELISTCOUNTRYCUSTOMERTYPENAME"/> <xsd:element ref="PLDTL_ACDINDICATOR"/> <xsd:element ref="PL_COUNTRYNAME"/> <xsd:element ref="ITM_PARTNUMBER"/> <xsd:element ref="ITM_ITEMNAME"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> <pricelistroot> <pricelist> <PL_PRICELISTCOUNTRYCUSTOMERTYPENAME>United States Direct To Reseller</PL_PRICELISTCOUNTRYCUSTOMERTYPENAME> <PLDTL_ACDINDICATOR>NONE</PLDTL_ACDINDICATOR> <PL_COUNTRYNAME>United States</PL_COUNTRYNAME> <ITM_PARTNUMBER>021-06069</ITM_PARTNUMBER> <ITM_ITEMNAME>Office Arabic CmprhnKit MVL CD</ITM_ITEMNAME> </pricelist> </pricelistroot> </xml>
YoniSion@gmail.com wrote: > Dim oSettings As New XmlReaderSettings > oSettings.ValidationType = ValidationType.Schema > oSettings.ValidationFlags = > XmlSchemaValidationFlags.ProcessInlineSchema > > Dim xmlr As XmlReader > xmlr = XmlReader.Create(reader, oSettings) > Dim myschema1 As XmlSchema = XmlSchema.Read(xmlr, > AddressOf ValidationCallback) > > so far, pretty much textboook code. problem is, it doesnt even begin > to validate! I get: > "The root element of a W3C XML Schema should be <schema> and its > namespace should be 'http://www.w3.org/2001/XMLSchema'." Not sure which text book suggests that code, you need a a different approach, see http://msdn.microsoft.com/en-us/library/8f0h7att(VS.80).aspx -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Hi Martin, thanks for your quick replay. so you suggest not to use XmlSchema for validating schema? there many samples online in which people use it. i tried the code you gave me. it works better in the sense that it doesnt give just one error and exsits... but even its warnings and errors are not the clearest.... is it suppose to validate the SCHEMA itself or the DATA as against a schema? thanks again! Jonathan
YoniSion@gmail.com wrote: > so you suggest not to use XmlSchema for validating schema? there many > samples online in which people use it. I thought you want to validate the XML you have posted against the inline schema it contains. If you want to validate only the schema itself then use an XmlSchemaSet to load the schema and then compile the XmlSchemaSet Dim schemaSet As New XmlSchemaSet() AddHandler schemaSet.ValidationEventHandler, AddressOf VHandler Using reader As XmlReader = XmlReader.Create("..\..\XMLFile1.xml") While reader.Read() If reader.NodeType = XmlNodeType.Element And reader.NamespaceURI = "http://www.w3.org/2001/XMLSchema" And reader.LocalName = "schema" Then schemaSet.Add(Nothing, reader.ReadSubtree()) End If End While End Using schemaSet.Compile() where VHandler is a ValidationEventHandler. But that approach is only necessary if all you want to do is validate the schema itself. If you want to validate the XML against the inline schema then use the code in the MSDN sample. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/