Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Desperate to compare .XSD To .XML

Status
Not open for further replies.

RDC

Programmer
Jan 6, 2001
55
US
Desperate to compare .XSD To .XML ..was told I could s'simply' do this with .NET's 'XML reader' ..I ahve both files.. and am going in circles.. deadkine tomoroww orning toshow their differences.. Can ayone PLEASE help me?Is is possible ..to do without code?
 
You have a deadline to do what exactly?

>> "deadkine tomoroww orning toshow their differences"

the difference of what?

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
An XSD is used to validate the XML. It's either valid, or it's not. Here's a sample of how to do it, tweaked a little bit from the online help:
Code:
   Imports System.IO
   Imports System.Xml
   Imports System.Xml.Schema
   Imports Microsoft.VisualBasic

   Private m_success As Boolean = true
   Private txtreader As XmlTextReader = Nothing
   Private reader As XmlValidatingReader = Nothing

   Private Sub Validate(filename As String)
      Try
         'Implement the readers.  Set the ValidationType.
         txtreader = New XmlTextReader(filename)
         reader = New XmlValidatingReader(txtreader)
         ' Leave .ValidationType as auto (the default)

         Console.WriteLine(ControlChars.Cr & "Validating XML file " & filename.ToString())
         m_success = True
         'Set the validation event handler.
         AddHandler reader.ValidationEventHandler, AddressOf ValidationCallBack
            
         ' Read XML data
         While reader.Read()
         End While 
         
         Console.WriteLine("Validation finished. Validation {0}", IIf(m_success, "successful", "failed"))
        
      Finally
         'Close the reader.
         If Not (reader Is Nothing) Then
            reader.Close()
         End If
      End Try 
   End Sub 'Validate

   'Snag the validation errors.
   Private Sub ValidationCallBack(sender As Object, args As ValidationEventArgs)
      m_success = False
        
      Console.Write(ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message)
   End Sub 'ValidationCallBack
Hope this helps.
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
BTW, the previous code assumes the XML already has namespace elements to point to the XSD. If it doesn't, you'll need to add them manually to the validating reader's schema collection.
Code:
   Dim xsc As New XmlSchemaCollection()
   xsc.Add("", "someschema.xsd")

   reader.Schemas.Add(xsc) '(reader is your validating reader from above)

   ' now read the XML data.
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Please help me... I have been trying and going in circles.... Presentation moved to Monday Jan. 5th... please help me stand a chance of surviving this task....


I have two files..
Schema.XSD
Client.XML


Schema Data needs to be readable without WEB tags
with ALL categorized data imported into Excel then into an Access Database as tables/fieldnames

Client Data needs to be readable without WEB tags
with ALL categorized data imported into Excel then into the applicable RESPECTIVE Access Database tables/fieldnames

I need to show FULL SCHEMA (all possibilities) in Access Database ..with data INSERTED from Client.XML wherever there is a match on:

FULL SCHEMA:Fieldname - TO - Client:Fieldname

 
Please help... desperate..even to get ANY data READABLE without tags into an Excel spreadsheet
 
I hate to sound rude, but did you read my earlier post?

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
I kept getting errors... I'm trying again.. I'll report back... Thank you for standing by Chip..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top