I wish I could say it worked for me.
Could not find schema information for the element 'details'. I've been
fighing with this for hours. This is ridiculous. Any ideas?
"Glenn" wrote:
>
> "Jack White" <no_spam@_nospam.com> wrote in message
> news:OZ5FkHXOHHA.1252@TK2MSFTNGP02.phx.gbl...
> >> Interesting, I can't remember ever having to do the
> >> "XmlSchemaValidationFlags.ReportValidationWarnings" thing. The method I
> >> use, which is almost definately slower given it doesn't use a reader, or
> >> if it does it's internal, is XmlDocument.Validate().
> >
> > Since none of the examples I've seen turn this flag on it leads me to
> > believe I have a problem somewhere. I shouldn't have to turn it on IOW if
> > nobody else has to.
> >
> >> Whenever a problem gets reported you can check
> >> ValidationEventArgs.Severity property to determine what action to take,
> >> if any.
> >
> > It always reports it as a warning. I originally thought it would be
> > reported as an error but apparently not. The problem is that you can't
> > distinguish between "acceptable" warnings generated while reading a
> > conforming ".xml" file (warnings I can safely ignore), and those that
> > really need to be treated as errors (normally because you're dealing with
> > a non-conforming ".xml" file). My testing shows that a conforming ".xml"
> > file generates no warnings however so I'll have to assume that any warning
> > is really an error and treat it that way. That may not be true however so
> > I may actually reject a conforming ".xml" file which will be a problem. I
> > can't seem to resolve the issue any other way however.
> >
> >> Was the schema inlined with the XML? If not, it'll infer the schema from
> >> the XML and won't throw an exception.
> >>
> >>
http://msdn2.microsoft.com/en-us/library/360dye2a.aspx > >
> > Even when I pass "XmlWriteMode.WriteSchema" to "WriteXml()" and later read
> > it back in, no errrors are generated.
> >
> >> I've distributed schemas with application code before now as a plain .xsd
> >> file, although this was to a well constrained user population. If your
> >> worried about people tampering with it, you could store it in a .resx
> >> file in your application.
> >
> > Tampering isn't an issue in my case but it's really an implemenation
> > detail so I wanted to avoid having to install it merely for this purpose.
> > I'm not sure what the accepted protocol is however . To validate an ".xml"
> > file, do you normally install its ".xsd" file for this purpose, assuming
> > you don't need it for anything else. In any case, my overall experience
> > with this situation has been very frustrating. I just want to validate an
> > ".xml" file but apparently I have to become an XML expert to do it. Thanks
> > again for your help though.
> >
>
> Don't worry about distributing an XSD with your application, it's just
> another file. And it's there for the purpose of making your application
> inputs more robust.
>
> Anyway, back your the validation problem...
>
> Before calling the myDataSet.ReadXml( reader ), you need to call while (
> reader.Read() ); Doing so will cause the reader to walk over the document
> and pick up any problems.
>
> I promise you, this version works, honest ;-)
>
> class Program
> {
> static void Main()
> {
> try
> {
> //WriteData();
>
> //Mangle the data by hand...
>
> ReadData();
> }
> catch ( Exception exception )
> {
> Console.WriteLine( exception.Message );
> }
> finally
> {
> Console.WriteLine( "\r\nFinished" );
> Console.ReadLine();
> }
>
> }
> static void WriteData()
> {
> MyDataSet testDataSet = new MyDataSet();
>
> testDataSet.MyTable.AddMyTableRow( "Abraham Lincoln" );
>
> testDataSet.WriteXml( "MyFile.xml", XmlWriteMode.IgnoreSchema );
> }
> /// <summary>
> ///
> /// </summary>
> static void ReadData()
> {
>
> MyDataSet myDataSet = new MyDataSet();
>
> XmlReaderSettings settings = new XmlReaderSettings();
>
> settings.Schemas.Add( null, "..\\..\\MyDataSet.xsd" );
> settings.ValidationType = ValidationType.Schema;
> settings.ValidationFlags |=
> XmlSchemaValidationFlags.ReportValidationWarnings;
> settings.ValidationEventHandler += new ValidationEventHandler(
> delegate( object sender, ValidationEventArgs args )
> {
> Console.WriteLine( "Severity : {0}\r\nMessage :{1}",
> args.Severity.ToString(), args.Message );
> } );
>
> XmlReader reader = XmlReader.Create( "MyFile.xml", settings );
>
> //this line is important!!!!
> while ( reader.Read() ) ;
>
> myDataSet.ReadXml( reader );
> }
> }
>
>
>
>