在记事本中验证xml文件++;但不是用C#

在记事本中验证xml文件++;但不是用C#,c#,xml,C#,Xml,我有以下xsd代码段: <xs:element name="TR" type="tns:blah" /> <xs:complexType name="blah"> <xs:sequence> <xs:element minOccurs="1" maxOccurs="1" name="Res" type="tns:Res" /> <xs:element minOccurs="0" maxOccur

我有以下xsd代码段:

    <xs:element name="TR" type="tns:blah" />
<xs:complexType name="blah">
    <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="Res" type="tns:Res" />
        <xs:element minOccurs="0" maxOccurs="1" name="SNotifications" type="tns:ArrayOfSNotification" />
        <xs:element minOccurs="0" maxOccurs="1" name="UNotifications" type="tns:ArrayOfUNotification" />
        <xs:element minOccurs="0" maxOccurs="1" name="TNotifications" type="tns:ArrayOfTNotification" />
    </xs:sequence>
</xs:complexType>
我已经加载了xml文档

任何帮助都将不胜感激

提前谢谢大家,, gmat请试试这个

public static bool IsValidXml(string xmlFilePath, string xsdFilePath)
{
    var xdoc = XDocument.Load(xmlFilePath);
    var schemas = new XmlSchemaSet();
    schemas.Add(namespaceName, xsdFilePath);

    Boolean result = true;
    xdoc.Validate(schemas, (sender, e) =>
         {
             result = false;
         });

    return result;
}

我们需要知道模式文档的targetNamespace,以及elementFormDefault的设置。几乎可以肯定,这是以下情况之一:

(a) 您有elementFormDefault=“qualified”,而架构的目标命名空间不是(在这种情况下,SNotifications元素应该位于目标命名空间中);或


(b) 您没有elementFormDefault=“qualified”(在这种情况下,SNotifications应该不在名称空间中)。

谢谢Janty,但很遗憾,我不能使用XDocument。我是针对.net 3.0版编写代码的。你有什么东西可以对抗旧版本吗?我使用了这个的xmldocument版本
xmlDocument.Schemas.Add("http://www.something.com/something", "path to xsd file");
    string result = string.Empty;
    xmlDocument.Validate((s, e) => result = string.Format("exception:{0}, exceptionmessage:{1}", e.Exception, e.Message));
public static bool IsValidXml(string xmlFilePath, string xsdFilePath)
{
    var xdoc = XDocument.Load(xmlFilePath);
    var schemas = new XmlSchemaSet();
    schemas.Add(namespaceName, xsdFilePath);

    Boolean result = true;
    xdoc.Validate(schemas, (sender, e) =>
         {
             result = false;
         });

    return result;
}