根据 xsd 作为字符串验证 xml 作为内存流

发布于 2024-12-08 18:29:05 字数 318 浏览 0 评论 0原文

我想根据 XSD (VB.NET) 验证 xml。我的函数如下所示:

Private Function ValidateXML(ByVal xml As MemoryStream, ByVal xsd As String) As    ArrayList
End Function

当我的 xml 是内存流/流(我使用流,因为我不需要存储 xml)并且我的 xsd 是一个字符串(我从网络服务获取我的 xsd)时,如何进行验证作为字符串,我不需要将其存储在文件中)?

非常感谢您的帮助!

I want to validate xml against XSD (VB.NET). My function look like this:

Private Function ValidateXML(ByVal xml As MemoryStream, ByVal xsd As String) As    ArrayList
End Function

How can I do the validation when my xml is a memorystream/stream (I use stream because I don’t need to store the xml) and my xsd is a string (I get my xsd from a web servise as a string, and I do not need to store it in a file)?

Thanks a lot for all help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞旧 2024-12-15 18:29:05

也许是这样的。

Imports System.Xml
Imports System.IO
Imports System.Xml.Schema

Module Module1

    Private isvalid As Boolean

    Sub Main()
        Dim xml As MemoryStream
        Dim xsd As String
        Dim settings As New XmlReaderSettings()
        settings.ValidationType = ValidationType.Schema
        settings.Schemas.Add("Schema:name", xsd)
        AddHandler settings.ValidationEventHandler, AddressOf MyValidationEventHandler

        Dim v = XmlReader.Create(xml, settings)

        While (v.Read())

        End While

        If isValid Then
            Console.WriteLine("Document is valid")
        Else
            Console.WriteLine("Document is invalid")
        End If
    End Sub



    Public Sub MyValidationEventHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
        isValid = False
        Console.WriteLine("Validation event\n" + args.Message)
    End Sub
End Module

Something like this perhaps.

Imports System.Xml
Imports System.IO
Imports System.Xml.Schema

Module Module1

    Private isvalid As Boolean

    Sub Main()
        Dim xml As MemoryStream
        Dim xsd As String
        Dim settings As New XmlReaderSettings()
        settings.ValidationType = ValidationType.Schema
        settings.Schemas.Add("Schema:name", xsd)
        AddHandler settings.ValidationEventHandler, AddressOf MyValidationEventHandler

        Dim v = XmlReader.Create(xml, settings)

        While (v.Read())

        End While

        If isValid Then
            Console.WriteLine("Document is valid")
        Else
            Console.WriteLine("Document is invalid")
        End If
    End Sub



    Public Sub MyValidationEventHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
        isValid = False
        Console.WriteLine("Validation event\n" + args.Message)
    End Sub
End Module
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文