Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / January 2008

Tip: Looking for answers? Try searching our database.

Validation of a stack of XSD files (.NET 2.0)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gxdata - 25 Jan 2008 04:34 GMT
I'm having a problem working out the classes and settings required to do
this validation:

There is a folder tree structure of 70+ XSD files that has a start point
(parent XSD) which relates to all of the others via include or import. Of
course a particular include may point to another XSD that itself has
includes. And so on.

The location of the XSD would be like C:\standard\folder1\first.xsd

I don't need to validate an XML file yet. It's just to check that the
existing stack of XSD files have correct relative addressing, etc.
The XmlResolver should be able to process the xs:include and xs:import
elements effectively.

Can someone help me with some starter code in VB.NET (2.0 preferably)?
Signature

Ian Thomas

Martin Honnen - 25 Jan 2008 12:48 GMT
> I'm having a problem working out the classes and settings required to do
> this validation:
[quoted text clipped - 12 lines]
>
> Can someone help me with some starter code in VB.NET (2.0 preferably)?

Set up an XmlSchemaSet with a ValidationEventHandler which outputs all
details:

        Dim schemaSet As New XmlSchemaSet()
        AddHandler schemaSet.ValidationEventHandler, AddressOf
ValidationHandler
        schemaSet.Add(Nothing, "..\..\XSDSchema1.xsd")
        schemaSet.Compile()

    Sub ValidationHandler(ByVal sender As Object, ByVal vargs As
ValidationEventArgs)
        Console.WriteLine("{0}: {1}; file: {2}; line: {3}; position:
{4}.", vargs.Severity, vargs.Message, vargs.Exception.SourceUri,
vargs.Exception.LineNumber, vargs.Exception.LinePosition)
    End Sub

That way you will be warned about any imports or includes that cannot be
resolved.

Of course you could as well load the main schema into the Visual Studio
2005 schema editor and it will show the warnings too.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

gxdata - 25 Jan 2008 15:36 GMT
Ok, that sort of works for me - thanks.
I am getting some schema compile warnings and errors, hence exception
messages.
However, the .sourceUri seems to be null - and it's the most useful thing to
look at.

Actually, I also used the ValidXSD class
(http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemaexception(VS
.80).aspx
)

Will these routines run through ALL of the XSD files, or stop on first
error?

In VS2005 or 2008, exactly what do I need to do to "load the main schema
into the schema editor"? I've not done that. Is it a rag & drop operation?

Thanks for your help.

Signature

Ian Thomas

>> I'm having a problem working out the classes and settings required to do
>> this validation:
[quoted text clipped - 34 lines]
> Of course you could as well load the main schema into the Visual Studio
> 2005 schema editor and it will show the warnings too.
Martin Honnen - 25 Jan 2008 15:46 GMT
> Ok, that sort of works for me - thanks.
> I am getting some schema compile warnings and errors, hence exception
[quoted text clipped - 7 lines]
> Will these routines run through ALL of the XSD files, or stop on first
> error?

If you set up a ValidationEventHandler then it should not stop on the
first error but continue to process the main schema and includes and
imports that work.

> In VS2005 or 2008, exactly what do I need to do to "load the main schema
> into the schema editor"? I've not done that. Is it a rag & drop operation?

Simply open the file in Visual Studio, for instance using
  Project -> Add existing item

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

gxdata - 25 Jan 2008 16:11 GMT
Martin
When running the code, I get a few (9) warnings and 3 errors - I haven't tracked down which XSD files they're in yet.

> Simply open the file in Visual Studio, for instance using
>   Project -> Add existing item
OK, I do that and see that the relatives paths are unresolved, in the top-most XSD file -
(sorry - thought I could send a small embedded image here - obviously not)
The wavy line under xs:import and xs:include indicates they're unresolved.
Clicking the menu XML>Schemas ... I can scroll down and Use that schema.
But I don't see how I can get any useful information out of this.
Signature

Ian Thomas

>> Ok, that sort of works for me - thanks.
>> I am getting some schema compile warnings and errors, hence exception
[quoted text clipped - 17 lines]
> Simply open the file in Visual Studio, for instance using
>   Project -> Add existing item
gxdata - 25 Jan 2008 16:20 GMT
OK - a bit dumb of me - Add As Link does it for me - ie, adds the file metadataEntity.XSD and the include are resolved OK.
Now, can you tell me how to make it check through all those include files and report errors?
(I'm learning a few skills here that I didn't think VS could do for me)

Signature

Ian Thomas

 Martin
 When running the code, I get a few (9) warnings and 3 errors - I haven't tracked down which XSD files they're in yet.

 > Simply open the file in Visual Studio, for instance using
 >   Project -> Add existing item
 OK, I do that and see that the relatives paths are unresolved, in the top-most XSD file -
 (sorry - thought I could send a small embedded image here - obviously not)
 The wavy line under xs:import and xs:include indicates they're unresolved.
 Clicking the menu XML>Schemas ... I can scroll down and Use that schema.
 But I don't see how I can get any useful information out of this.
 --
 Ian Thomas

 "Martin Honnen" <mahotrash@yahoo.de> wrote in message news:%23P84$l2XIHA.3696@TK2MSFTNGP03.phx.gbl...
 >> Ok, that sort of works for me - thanks.
 >> I am getting some schema compile warnings and errors, hence exception
 >> messages.
 >> However, the .sourceUri seems to be null - and it's the most useful thing to
 >> look at.
 >>
 >> Actually, I also used the ValidXSD class
 >> (http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemaexception(VS
.80).aspx
)
 >>
 >> Will these routines run through ALL of the XSD files, or stop on first
 >> error?
 >
 > If you set up a ValidationEventHandler then it should not stop on the
 > first error but continue to process the main schema and includes and
 > imports that work.
 >
 >> In VS2005 or 2008, exactly what do I need to do to "load the main schema
 >> into the schema editor"? I've not done that. Is it a rag & drop operation?
 >
 > Simply open the file in Visual Studio, for instance using
 >   Project -> Add existing item
 >
 >
 > --
 >
 > Martin Honnen --- MVP XML
 > http://JavaScript.FAQTs.com/ 
Martin Honnen - 25 Jan 2008 16:26 GMT
> When running the code, I get a few (9) warnings and 3 errors - I haven't
> tracked down which XSD files they're in yet.

SourceUri on the exception should tell. Not sure why that does not work
for you.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

gxdata - 25 Jan 2008 16:45 GMT
Confusing. A different file gives warnings, errors interactively (ie,
loading the XSD file as a link into VS2008 Beta2), and compiling the code.
From my reading, it's not possible to print out the name of each schema file
that is loaded subsequent to the first (ie, by import or include), nor to
obtain a full list of individiual schema files that make up the fully-loaded
schemaset.
Is that right? Or is there a way I haven't found yet?
I'm looking at 3.5 framework documentation.
Signature

Ian Thomas

>> When running the code, I get a few (9) warnings and 3 errors - I haven't
>> tracked down which XSD files they're in yet.
>
> SourceUri on the exception should tell. Not sure why that does not work
> for you.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.