"无法找到元素的架构信息......"在XML文档中

时间:2014-07-09 19:33:02

标签: c# xml validation

我正在尝试验证GXL XML Validator。

<?xml version="1.0"?>
<!DOCTYPE gxl SYSTEM "http://www.gupro.de/GXL/gxl-1.0.dtd">
<!-- attributes 05.02.2002  -->
<gxl xmlns:xlink="http://www.w3.org/1999/xlink">
    <graph id="attributes-instance">
        <type xlink:href="../../../schema/gxl/attributes/attributesSchema.gxl#attributesSchema"/>
        <node id="p">
            <type xlink:href="../../../schema/gxl/attributes/attributesSchema.gxl#Prog"/>
            <attr name="file">
                <seq>
                    <string>Ric</string>
                    <string>Andy</string>
                    <string>Susan</string>
                    <string>Andreas</string>
                </seq>
            </attr>
        </node>
    </graph>
</gxl>

当我通过在线解析器Validome时,它表明该文档是有效的,没有任何警告或错误。但是,当我通过C#XML Validator时,该文件仍然有效,但我收到以下警告。

Warning: Line: 4, Position: 2 "Could not find schema information for the element 'gxl'."
Warning: Line: 5, Position: 3 "Could not find schema information for the element 'graph'."
Warning: Line: 5, Position: 9 "Could not find schema information for the attribute 'id'."
Warning: Line: 75, Position: 2 "Could not find schema information for the attribute 'edgeids'."
Warning: Line: 76, Position: 2 "Could not find schema information for the attribute 'hypergraph'."
Warning: Line: 77, Position: 2 "Could not find schema information for the attribute 'edgemode'."
Warning: Line: 6, Position: 4 "Could not find schema information for the element 'type'."
Warning: Line: 6, Position: 9 "Could not find schema information for the attribute 'http://www.w3.org/1999/xlink:href'."
Warning: Line: 67, Position: 2 "Could not find schema information for the attribute 'http://www.w3.org/1999/xlink:type'."
Warning: Line: 7, Position: 4 "Could not find schema information for the element 'node'."
Warning: Line: 7, Position: 9 "Could not find schema information for the attribute 'id'."
Warning: Line: 8, Position: 5 "Could not find schema information for the element 'type'."
Warning: Line: 8, Position: 10 "Could not find schema information for the attribute 'http://www.w3.org/1999/xlink:href'."
Warning: Line: 67, Position: 2 "Could not find schema information for the attribute 'http://www.w3.org/1999/xlink:type'."
Warning: Line: 9, Position: 5 "Could not find schema information for the element 'attr'."
Warning: Line: 9, Position: 10 "Could not find schema information for the attribute 'name'."
Warning: Line: 10, Position: 6 "Could not find schema information for the element 'seq'."
Warning: Line: 11, Position: 7 "Could not find schema information for the element 'string'."
Warning: Line: 12, Position: 7 "Could not find schema information for the element 'string'."
Warning: Line: 13, Position: 7 "Could not find schema information for the element 'string'."
Warning: Line: 14, Position: 7 "Could not find schema information for the element 'string'."
Validatoin Complete:Valid XMLFile

无论如何都要告诉两个验证器是否正在产生相同的警告,只是Validome没有报告它或者验证器之间有什么不同。

另外,为什么“找不到元素的架构信息......&#34;是一个警告,而不是一个更严重的错误,您不需要架构信息来获得有用的XML文档吗?

C#Validator

 // Set the validation settings.
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.DtdProcessing = DtdProcessing.Parse;
        settings.ValidationType = ValidationType.Schema;
        settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
        settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
        settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
        settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;


        settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);

        // Create the XmlReader object.
        XmlReader reader = XmlReader.Create(path, settings);

        try
        {
            // Parse the file. 
            while (reader.Read()) ;
            if (isValid)
            {
                Console.WriteLine("Validatoin Complete:Valid XMLFile");
            }
            else
            {
                Console.WriteLine("Validatoin Complete: Not a Valid XMLFile");
            }
        }
        catch (System.Xml.XmlException e)
        {
            //Displays any parsing errors
            Console.WriteLine("Parsing error:" + e.Message);
            isValid = false;
        }

  // Display any warnings, general errors, and validation errors .
    // If there are only warnings an xmldocument is still valid
    private static void ValidationCallBack(object sender, ValidationEventArgs args)
    {
         if (args.Severity == XmlSeverityType.Warning )
        {
            Console.WriteLine("Warning: " + String.Format("Line: {0}, Position: {1} \"{2}\"",
                args.Exception.LineNumber, args.Exception.LinePosition,
args.Exception.Message));
        }
        else if (args.Severity == XmlSeverityType.Error)
        {
            Console.WriteLine("Error: " + String.Format("Line: {0}, Position: {1} \"{2}\"",
                args.Exception.LineNumber, args.Exception.LinePosition,
args.Exception.Message));
            isValid = false;
        }
        else
        {
            Console.WriteLine("Validation error: " + args.Message);
            isValid = false;
        }

    }
  }

0 个答案:

没有答案