473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB-APP: XML Validates in XMLspy but not VB

Hi all

As part of a project I have a vb program that takes an XML document (payload-XML), which contains a lot of data, but no namespaces. It is run through an XSLT transformation which creates an XML message (Message XML) to be dilivered to another system, then that XML message is validated in code.

The Message XML to the other system does use namespaces and XSD validation, and one of its XML fields is the original XML document, in it's entrity.

The Code-based validator I am using is based of one of the many VB.net 1.1 code examples avilable online - using an XMLValidating reader that has the schema assign to it, reads the xml from an xmlreader and creates a validation event when there is a problem.

The Message XML fields are all typed, and the type of the Payload XML field is xs:anytype <- the payload XML is supposed to be trated like a black box and ignored during XSD validation.

Now After a bit of work it validates most of the message, but fails when it gets to the payload-XML tag. Giving errors that the payload XML tags have not been declared.

However, if I save the XML document to disk, load it in XMLSpy and use that to validate it validates fine.

Sample Message
[HTML]
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<Message xsi:schemaLocation="http://[PrefixURL]/Message C:/[FilePath]/XSD/message.xsd" xmlns="http://[PrefixURL]/Message" xmlns:cmh="http://[PrefixURL]/CMH" xmlns:IT01407="http://[PrefixURL]/IT01407" xmlns:types="http://[PrefixURL]/Types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cmh:Cmh>
<cmh:InterfaceId>IT01407</cmh:InterfaceId>
<cmh:ServiceName>NOT.USED</cmh:ServiceName>
<cmh:Version>2.0.1</cmh:Version>
<cmh:To Destination="SERVER2" />
<cmh:From SourceAddress="UK003680" ComponentVersion="2.0.1" ComponentId="SERVER5" />
<cmh:Tracking>
<cmh:Item Timestamp="2007-05-02 11:22:82.054" AppInfo="TO.BE.CHANGED" Event="SENDMESSAGE.IT01407" />
</cmh:Tracking>
</cmh:Cmh>
<Body>
<IT01407:IT01407Body>
<IT01407:ClientSurname>DILLON</IT01407:ClientSurname>
<IT01407:ClientForename>THERESA</IT01407:ClientForename>
<IT01407:NfdsApplied>false</IT01407:NfdsApplied>
<IT01407:ReportData>
<payloadXML>
<PayloadXML-Tag-2>There are a lot of tags in payloadXML, none of them have any namespaces</PayloadXML-Tag-2>
</payloadXML>
</IT01407:ReportData>
</IT01407:IT01407Body>
</Body>
</Message>
[/HTML]
As said: <IT01407:ReportData> is of xs:Anytype as we want the tags contents to be treated as a black box. Within it is a large XML document that has no namespaces. If the PayloadXML is removed then the document validates fine in code.
With or without the payload it validates fine in XMLSpy (which is the expected behaviour)

Error returned by the code validator (a list of the event-args.message results):
The 'payloadXML' element is not declared. An error occurred at , (22, 10).(Line,Position)
The 'PayloadXML-Tag-2' element is not declared. An error occurred at , (23, 12).(Line,Position)
....
continuing until it has errored every line in payloadXML


My Guess is I am missing an "ignore everything in this tag" notation somewhere, but am not sure where, XML spy just does it by default, vb doesn't.


Validator VB code:
Expand|Select|Wrap|Line Numbers
  1. Private _bValid as boolean
  2. Private _oErrors as StringCollection
  3.  
  4. Public Function ValidateXMLAgainstXSD(ByVal oXMLDoc As XmlDocument, ByVal sXSDPath As String) As Boolean
  5.  
  6. Dim oStream As MemoryStream
  7. Dim oValidator As XmlValidatingReader
  8. Dim oXMLReader As XmlTextReader
  9. Dim oSchemaReader As XmlTextReader
  10. Dim oSchema As XmlSchema
  11. Dim oErrorMessage As Text.StringBuilder
  12. Dim sError As String
  13.  
  14. Try
  15.     _oErrors = New StringCollection
  16.     oSchema = New XmlSchema
  17.     oStream = New MemoryStream
  18.     oSchemaReader = New XmlTextReader(sXSDPath)   
  19.     oXMLDoc.Save(oStream)
  20.     oStream.Position = 0
  21.     oXMLReader = New XmlTextReader(oStream)
  22.  
  23.     oSchema.Read(oSchemaReader, AddressOf Validator_ValidationEventHandler)
  24.  
  25.     oValidator = New XmlValidatingReader(oXMLReader)
  26.     AddHandler oValidator.ValidationEventHandler, AddressOf Validator_ValidationEventHandler
  27.     oValidator.Schemas.Add(oSchema)
  28.     oValidator.ValidationType = ValidationType.Schema
  29.     _bValid = True
  30.  
  31.     While oValidator.Read()       
  32.     End While
  33.  
  34.     If Not _bValid Then
  35.         oErrorMessage = New Text.StringBuilder
  36.         oErrorMessage.Append("XML Validation Error: " & Chr(13))
  37.         For Each sError In _oErrors
  38.             oErrorMessage.Append(sError & Chr(13))
  39.         Next
  40.         ErrorLogging.LogError(oErrorMessage.ToString)
  41.     End If
  42.  
  43.     oSchemaReader.Close()
  44.     Return _bValid
  45.  
  46. Catch ex As Exception
  47.     oSchemaReader.Close()
  48.     ErrorLogging.LogError(ex)
  49. End Try
  50. End Function
  51.  
  52. Private Sub Validator_ValidationEventHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
  53. _bValid = False
  54. _oErrors.Add(args.Message & "(Line,Position)")
  55. End Sub
  56.  
May 2 '07 #1
0 967

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Terry | last post by:
Hi, I need some feedback. We are converting to .Net and we are trying to decide on whether to use VB.net or C#.net. As far as our current systems, they will probably be rewritten in ASP.Net. I...
7
by: Simon Peng | last post by:
-- ---------------- Simon Peng xqpeng@tsinghua.org.cn
5
by: Saga | last post by:
Hi all, I just read the thread by the same name posted on Jun 15, 9:45 AM, but I am looking at it from a different point of view. I came across this question in terms of functionality. Are VB and...
13
by: Arsalan | last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax ? Can anything done in C# which cannot be done in VB.NET?
72
by: Robin Tucker | last post by:
I need to find some documents/research for my manager about VB.NET v C# use. I've noticed that there are many more people using C# than VB.NET, that there seem to be more job vacancies specifying...
28
by: Andy | last post by:
Any good resources regarding benefitis by using C3 over VB? /Andy
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
2
by: D H | last post by:
Hi, Hi, I was looking for your opinion on VB.NET - its long-term prospects, etc. Sorry this is vague, but it's not meant to be a troll. It's a pro-VB.NET post actually. I haven't used VB or...
19
by: lonelyplanet | last post by:
Hi, I'm studying for 70-306 using the book "MCAD/MCSD Visual Basic .NET Windows Applications" published by McGraw Hill (ISBN: 0-07-212583-7). I found the book has no programming exercise...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.