0

以下の警告を取り除くのを手伝っていただければ幸いです。良いドキュメントを見つけることができませんでした。警告はprivate void ValidateConfiguration( XmlNode section )セクションに集中しているため、以前にこれに遭遇したことがある場合は、これに答えるのがそれほど難しくないことを願っています.

ありがとう!

'System.Configuration.ConfigurationException.ConfigurationException(string)' is obsolete: 'This class is obsolete, to create a new exception create a System.Configuration!System.Configuration.ConfigurationErrorsException'   

'System.Xml.XmlValidatingReader' is obsolete: 'Use XmlReader created by XmlReader.Create() method using appropriate XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202'    

private void ValidateConfiguration( XmlNode section )
{                
    // throw if there is no configuration node.
    if( null == section )
    {
        throw new ConfigurationException("The configuration section passed within the ... class was null ... there must be a configuration file defined.", section );
    }
    //Validate the document using a schema
    XmlValidatingReader vreader = new XmlValidatingReader( new XmlTextReader( new StringReader( section.OuterXml ) ) );
    //  open stream on Resources; the XSD is set as an "embedded resource" so Resource can open a stream on it
    using (Stream xsdFile = XYZ.GetStream("ABC.xsd"))
    using (StreamReader sr = new StreamReader(xsdFile))
    {
        vreader.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
        vreader.Schemas.Add(XmlSchema.Read(new XmlTextReader(sr), null));
        vreader.ValidationType = ValidationType.Schema;
        // Validate the document
        while (vreader.Read()) { }

        if (!_isValidDocument)
        {
            _schemaErrors = _sb.ToString();
            throw new ConfigurationException("XML Document not valid");
        }
    }
}

// Does not cause warnings.
private void ValidationCallBack( object sender, ValidationEventArgs args )
{
    //  check what KIND of problem the schema validation reader has;
    //  on FX 1.0, it gives a warning for "<xs:any...skip" sections.  Don't worry about those, only set validation false
    //  for real errors
    if( args.Severity == XmlSeverityType.Error )
    {
        _isValidDocument = false;
        _sb.Append( args.Message + Environment.NewLine );
    }
}
4

2 に答える 2

1

基本的に、廃止されたのXmlReaderSettings代わりにを使用するように指示しています。XmlValidatingReader

個人的には変換を行うつもりはありません。実際に変換を行うことは、コーディングの開発に役立つと思います。そのため、いくつかのリソースを次に示します。

メソッドのオーバーロードXmlReader.Create()、特にthis oneを見てください。

XmlReaderSettings次に、クラスに関連付けられているさまざまなプロパティを見てください: http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings_members.aspx

試してみて、何が起こるかを見て、まだ問題がある場合は、別の質問をしてください:)

HTH

于 2010-05-04T22:45:52.433 に答える
1
  1. throw new ConfigurationException(....) と 置き換えます

    throw new ConfigurationErrorsException(....)

  2. XmlValidatingReader vreader = new XmlValidatingReader(...) と置き換えます


var vreader = XmlReader.Create(new StringReader(section.OuterXml), 
                               new XmlReaderSettings
                               {
                                  ValidationType = ValidationType.Schema
                               });
于 2010-05-04T22:51:17.727 に答える