P
Piotrekk
Hi
I have the following XML document and corresponding XSD schema.
<?xml version="1.0" encoding="utf-8"?>
<A>
<B></B>
<C>
<A/>
</C>
</A>
---------------------------
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/
XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://
www.w3.org/2001/XMLSchema">
<xs:complexType name="A">
<xs:sequence>
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="B"
type="B" />
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="C"
type="C" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="B">
<xs:sequence>
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="A"
type="A" />
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="C"
type="C" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="C">
<xs:sequence>
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="A"
type="A" />
</xs:sequence>
</xs:complexType>
<xs:element name="A" type="A"/>
</xs:schema>
------------------------------------------------------------
When i test the XML against the schema bu using the following code, I
am getting:
Error :Could not find schema information for the element 'A'.
Error :Could not find schema information for the element 'B'.
Error :Could not find schema information for the element 'C'.
Error :Could not find schema information for the element 'A'.
All ok
CODE:
static void Main(string[] args)
{
XmlTextReader r = new XmlTextReader("doc.xml");
XmlValidatingReader validator = new
XmlValidatingReader(r);
validator.ValidationType = ValidationType.Schema;
XmlSchemaCollection schemas = new XmlSchemaCollection();
schemas.Add(null, "schema.xsd");
validator.Schemas.Add(schemas);
validator.ValidationEventHandler += new
ValidationEventHandler(validator_ValidationEventHandler);
try
{
while (validator.Read()) { }
}
catch (XmlException err)
{
Console.WriteLine("Validation error");
Console.WriteLine(err.Message);
}
finally
{
validator.Close();
}
Console.WriteLine("All ok");
}
static void validator_ValidationEventHandler(object sender,
ValidationEventArgs e)
{
Console.WriteLine("Error :" + e.Message);
}
What does the error mean?
Best Regards
Piotr Kolodziej
I have the following XML document and corresponding XSD schema.
<?xml version="1.0" encoding="utf-8"?>
<A>
<B></B>
<C>
<A/>
</C>
</A>
---------------------------
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/
XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://
www.w3.org/2001/XMLSchema">
<xs:complexType name="A">
<xs:sequence>
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="B"
type="B" />
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="C"
type="C" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="B">
<xs:sequence>
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="A"
type="A" />
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="C"
type="C" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="C">
<xs:sequence>
<xs:element nillable="true" minOccurs="0" maxOccurs="1" name="A"
type="A" />
</xs:sequence>
</xs:complexType>
<xs:element name="A" type="A"/>
</xs:schema>
------------------------------------------------------------
When i test the XML against the schema bu using the following code, I
am getting:
Error :Could not find schema information for the element 'A'.
Error :Could not find schema information for the element 'B'.
Error :Could not find schema information for the element 'C'.
Error :Could not find schema information for the element 'A'.
All ok
CODE:
static void Main(string[] args)
{
XmlTextReader r = new XmlTextReader("doc.xml");
XmlValidatingReader validator = new
XmlValidatingReader(r);
validator.ValidationType = ValidationType.Schema;
XmlSchemaCollection schemas = new XmlSchemaCollection();
schemas.Add(null, "schema.xsd");
validator.Schemas.Add(schemas);
validator.ValidationEventHandler += new
ValidationEventHandler(validator_ValidationEventHandler);
try
{
while (validator.Read()) { }
}
catch (XmlException err)
{
Console.WriteLine("Validation error");
Console.WriteLine(err.Message);
}
finally
{
validator.Close();
}
Console.WriteLine("All ok");
}
static void validator_ValidationEventHandler(object sender,
ValidationEventArgs e)
{
Console.WriteLine("Error :" + e.Message);
}
What does the error mean?
Best Regards
Piotr Kolodziej