Closed Thread
Results 1 to 6 of 6

Thread: Help with Application Logic for .NET 2.0

  1. #1
    hoser2001's Avatar
    hoser2001 is offline Programmer
    Join Date
    Jul 2006
    Posts
    175
    Rep Power
    0

    Help with Application Logic for .NET 2.0

    Here is what I'm trying to do:

    1.) I have an application that is able to produce an xml document, and xsd and zips the two files together.
    2.) Using remoting I send the contents of the zip file to a server application.
    3.) My server application uncompresses the information and now has the xml and xsd file.

    My question is how do I now use the xsd to validate the xml. Both files are in memory.

    Also: I understand it doesn't make sense to send an xsd with every xml document, but for my purposes it does... don't ask....

    I'm not even sure if this is the right area to post this question, if not I'm sorry.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    falco85 is offline Programmer
    Join Date
    Apr 2006
    Posts
    105
    Rep Power
    0
    This should help you:

    XML UI: from XSD to XML

  4. #3
    OthelloNYC is offline Newbie
    Join Date
    Jul 2007
    Posts
    16
    Rep Power
    0
    Quote Originally Posted by hoser2001 View Post
    3.) My server application uncompresses the information and now has the xml and xsd file.
    --------------------------------------------------------------------------
    Both files are in memory.
    Are both files in memory, or do you still have them physically? if the latter, I have this code:
    -------------------------------------------------------------------------
    Imports System.Xml
    Imports System.Xml.Schema

    Public Class XMLValidator


    Public Sub New()
    End Sub

    Public Function Validate(ByVal fileName As String) As Boolean
    If SchemaCollection Is Nothing Then
    Throw New Exception("Property 'Schema' not set")
    End If
    Dim ValidatingReader As XmlValidatingReader

    Try
    ValidatingReader = New XmlValidatingReader(New XmlTextReader(fileName))
    ValidatingReader.Schemas.Add(SchemaCollection)
    ValidatingReader.ValidationType = ValidationType.Schema
    ' Set the validation event handler
    Dim valdel As ValidationEventHandler = New ValidationEventHandler(AddressOf ValidationEvent)

    AddHandler ValidatingReader.ValidationEventHandler, valdel

    ' Read XML data
    While ValidatingReader.Read()
    End While
    Finally
    If Not ValidatingReader Is Nothing Then
    ValidatingReader.Close()
    End If
    End Try

    Return Message Is Nothing

    End Function

    Public Sub ValidationEvent(ByVal errorid As Object, ByVal args As ValidationEventArgs)
    ' Missing schema
    If (args.Severity = XmlSeverityType.Warning) Then
    Message = Message + "No schema found to enforce validation."
    Message = Message + vbCrLf
    ' Not a well formed XML
    ElseIf (args.Severity = XmlSeverityType.Error) Then
    Message = Message + args.Message
    Message = Message + vbCrLf
    End If
    ' XSD schema validation error
    If Not (args.Exception Is Nothing) Then
    ' Message = Message + args.Exception.ToString()
    Message = Message + "My guess. Line#: " + CType(args.Exception.LineNumber - 2, String)
    Message = Message + vbCrLf
    End If
    MessageCount += 1
    End Sub

    Public ReadOnly Property ErrorMessage() As String
    Get
    Return Message
    End Get
    End Property

    Public WriteOnly Property Schema() As String
    Set(ByVal Value As String)
    Try
    SchemaCollection = New XmlSchemaCollection
    Dim Reader As New XmlTextReader(Value)
    If SchemaCollection.Add(Nothing, Reader) Is Nothing Then
    Throw New Exception("Schema file not loaded")
    End If
    Reader.Close()
    Catch ex As Exception
    SchemaCollection = Nothing
    Throw ex
    End Try
    End Set
    End Property
    Public ReadOnly Property Errors() As Integer
    Get
    Return Me.MessageCount
    End Get
    End Property

    Private SchemaCollection As XmlSchemaCollection

    Private Message As String = Nothing
    Private MessageCount As Integer = 0
    End Class
    ---------------------------------------------------------------------------
    If not, you can try messing with the IO streams to make them direct memory strings loaded into streams.

  5. #4
    hoser2001's Avatar
    hoser2001 is offline Programmer
    Join Date
    Jul 2006
    Posts
    175
    Rep Power
    0
    thank you

  6. #5
    OthelloNYC is offline Newbie
    Join Date
    Jul 2007
    Posts
    16
    Rep Power
    0
    No problem. Let me know how much you had to adapt that!

  7. #6
    hoser2001's Avatar
    hoser2001 is offline Programmer
    Join Date
    Jul 2006
    Posts
    175
    Rep Power
    0
    I already have something simliar that uses file paths so between all the references I have, I'm sure I'll come up with something.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Logic
    By cjrose77 in forum PHP Development
    Replies: 7
    Last Post: 08-31-2011, 08:05 AM
  2. Beginner C# : Application Launcher (Console Application)
    By Jarryd in forum CSharp Tutorials
    Replies: 7
    Last Post: 06-19-2011, 10:49 AM
  3. The Logic behind solving Logic?
    By Pyro.699 in forum General Programming
    Replies: 2
    Last Post: 04-18-2010, 09:50 PM
  4. Need a better logic...
    By veda87 in forum C and C++
    Replies: 2
    Last Post: 08-18-2009, 10:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts