Привет всем, у меня есть XML
файл следующим образом
Имя XML
XMLFile2.xml
<?xml version="1.0"?>
<Product ProductID="123"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Product.xsd">
<ProductName>XYZ</ProductName>
</Product>
Мой XSD
выглядит следующим образом
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Product"
targetNamespace="http://tempuri.org/Product.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/Product.xsd"
xmlns:mstns="http://tempuri.org/Product.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="ProductName" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="ProductID" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
Это мой код
string strPath = Server.MapPath("XMLFile2.xml");
XmlTextReader r = new XmlTextReader(strPath);
XmlValidatingReader v = new XmlValidatingReader(r);
v.ValidationType = ValidationType.Schema;
v.ValidationEventHandler +=
new ValidationEventHandler(MyValidationEventHandler);
while (v.Read())
{
}
v.Close();
if (isValid)
Response.Write("Document is valid");
else
Response.Write("Document is invalid");
Я получаю следующие ошибки
Validation event
The targetNamespace parameter '' should be the same value as the targetNamespace 'http://tempuri.org/Product.xsd' of the schema.Validation event
The 'Product' element is not declared.Validation event
Could not find schema information for the attribute 'ProductID'.Validation event
The 'ProductName' element is not declared.Document is invalid
Может кто-нибудь сказать, где я ошибся.