XML Validation problem

J

John S

I have a web servicce which receives an XMLDocument and then uses the
XMLDocument.Validate method to make sure it is valid.

I'm then using a ValidationEventHandler to pick up any failures.

I need to be able to store those failures in some way so that they can be
returned to the calling process.

I tried using an arraylist but VB tells me it has to be shred for the
eventhandler and the other methods in the web service to all access the data.

However, making it shared means that any other calls coming in at the same
time will also access and write to it. Deffinitely not what I need!

Can anyone tell me how to do this correctly?

Thanks
 
J

John S

That sounds like what I'm trying to do.

However, I'm using VB and although I tried to convert your example I didn't
have much luck.

Can you help?

Thanks
 
S

Steven Cheng

Thanks for your quick reply John,

No problem. Here is the VB.NET version of my test code snippet:


=======helper class===========
Public Class MyValidationHelper

Public Messages As New System.Collections.Generic.List(Of String)

Public Sub ValidationHandler(ByVal sender As Object, ByVal e As
System.Xml.Schema.ValidationEventArgs)

Messages.Add(e.Message)

End Sub

End Class
=====================


======use helper class in web method =======
<WebMethod()> _
Public Function TestWebMethod(ByVal doc As System.Xml.XmlDocument) As
String

Dim vhelper As New MyValidationHelper()
'validatethe xml first
doc.Validate(AddressOf vhelper.ValidationHandler)

Return "Validation Result, error count: " & vhelper.Messages.Count

End Function
End Class
==================

If there is anything else unclear, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
 
J

John S

That did the job.

Many thanks

"Steven Cheng" said:
Thanks for your quick reply John,

No problem. Here is the VB.NET version of my test code snippet:


=======helper class===========
Public Class MyValidationHelper

Public Messages As New System.Collections.Generic.List(Of String)

Public Sub ValidationHandler(ByVal sender As Object, ByVal e As
System.Xml.Schema.ValidationEventArgs)

Messages.Add(e.Message)

End Sub

End Class
=====================


======use helper class in web method =======
<WebMethod()> _
Public Function TestWebMethod(ByVal doc As System.Xml.XmlDocument) As
String

Dim vhelper As New MyValidationHelper()
'validatethe xml first
doc.Validate(AddressOf vhelper.ValidationHandler)

Return "Validation Result, error count: " & vhelper.Messages.Count

End Function
End Class
==================

If there is anything else unclear, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
 
S

Steven Cheng

You're welcome:)

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top