473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlTextReader vs. XmlValidatingRe ader

I am a bit puzzled about the differences between
XmlTextReader and XmlValidatingRe ader. I have been able
to successfully load a DataSet object from and XML file
via the text reader. However, when I replace it (xtr) by
a validating reader (vxtr), the DataSet object is Nothing.
No errors have been indicated by the validating reader
(and the XML file is valid for its embedded <schema> ).

So what gives?

[The real problem I'm trying to solve has to do with
<xs:import>'s in the schema, but that is another post.]
dsResults.Clear ()
' A FileStream is needed to read the XML document.
Dim filename As String = "SmfDg.xml"
Dim fs As New FileStream(file name, FileMode.Open)
Dim xtr As New XmlTextReader(f s)
Try
Dim vxtr As XmlValidatingRe ader = New
XmlValidatingRe ader(xtr)
vxtr.Validation Type = ValidationType. None
Dim xsc As New XmlSchemaCollec tion
xsc.Add
("http://vanguard.com/fima2/TransactionType s.xsd", "C:\\Fim
a2\\Solutions\\ Projects\\Commo n\\DataSets\\Tr ansactions\\"
& "TransactionTyp es.xsd")
xsc.Add
("http://vanguard.com/fima2/SmfDataSet.xsd" , "C:\\Fima2
\\Solutions\\Pr ojects\\Common\ \DataSets\\Smf\ \"
& "SMFDataSet.xsd ")
vxtr.Schemas.Ad d(xsc)

Dim ser As XmlSerializer = New XmlSerializer
(GetType(DataSe t))
'Your results may vary between xtr and vxtr
dsResults = CType(ser.Deser ialize(vxtr),
DataSet)

dgAuditDetail.D ataSource = dsResults
dgAuditDetail.D ataMember = dsResults.Table s
(0).TableName

Catch ex As Exception
Trace.WriteLine (ex.ToString)
Finally
fs.Close()
End Try
Nov 12 '05 #1
2 2257
You don't specify a callback handler to catch any exceptions that are
thrown - so you won't get any messages and you're right, it will be null if
validation fails.

AddHandler reader.Validati onEventHandler, AddressOf Me.ValidationEv entHandle

.. . .

'Display the validation error.
Private Sub ValidationEvent Handle(sender As Object, args As
ValidationEvent Args)
m_success = False
Console.WriteLi ne(ControlChars .CrLf & ControlChars.Ta b & "Validation
error: " & args.Message)
End Sub 'ValidationEven tHandle

.. . .

Steven, XmlInsider
http://venturetogether.com
"Ed Bacon" <Ed********@van guard.com> wrote in message
news:d4******** *************** *****@phx.gbl.. .
I am a bit puzzled about the differences between
XmlTextReader and XmlValidatingRe ader. I have been able
to successfully load a DataSet object from and XML file
via the text reader. However, when I replace it (xtr) by
a validating reader (vxtr), the DataSet object is Nothing.
No errors have been indicated by the validating reader
(and the XML file is valid for its embedded <schema> ).

So what gives?

[The real problem I'm trying to solve has to do with
<xs:import>'s in the schema, but that is another post.]
dsResults.Clear ()
' A FileStream is needed to read the XML document.
Dim filename As String = "SmfDg.xml"
Dim fs As New FileStream(file name, FileMode.Open)
Dim xtr As New XmlTextReader(f s)
Try
Dim vxtr As XmlValidatingRe ader = New
XmlValidatingRe ader(xtr)
vxtr.Validation Type = ValidationType. None
Dim xsc As New XmlSchemaCollec tion
xsc.Add
("http://vanguard.com/fima2/TransactionType s.xsd", "C:\\Fim
a2\\Solutions\\ Projects\\Commo n\\DataSets\\Tr ansactions\\"
& "TransactionTyp es.xsd")
xsc.Add
("http://vanguard.com/fima2/SmfDataSet.xsd" , "C:\\Fima2
\\Solutions\\Pr ojects\\Common\ \DataSets\\Smf\ \"
& "SMFDataSet.xsd ")
vxtr.Schemas.Ad d(xsc)

Dim ser As XmlSerializer = New XmlSerializer
(GetType(DataSe t))
'Your results may vary between xtr and vxtr
dsResults = CType(ser.Deser ialize(vxtr),
DataSet)

dgAuditDetail.D ataSource = dsResults
dgAuditDetail.D ataMember = dsResults.Table s
(0).TableName

Catch ex As Exception
Trace.WriteLine (ex.ToString)
Finally
fs.Close()
End Try

Nov 12 '05 #2
I am sorry I did not paste in all of the code. I do (did)
have a ValidationEvent Handler. It is not called (even if
I set the ValidationType to something other than None),
and that is the puzzle. No event, no exception but
dsResult is Nothing.

Again sorry I did excluded that detail.
Ed
-----Original Message-----
You don't specify a callback handler to catch any exceptions that arethrown - so you won't get any messages and you're right, it will be null ifvalidation fails.

AddHandler reader.Validati onEventHandler, AddressOf Me.ValidationEv entHandle


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1851
by: MT | last post by:
Hi, I am currently validating an XML file against a Schema using XMLValidatingReader. The schema actually contains ranges for particular elements and I have been using it to detect range errors before it gets to my program. The way the rangechecking works is that every element that needs range checking is defined as an element with a particular type in the XSD. For example, <xs:element name="Row" maxOccurs="48">
4
11402
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This should have worked fine since the class in question was already being serialized and deserialized as part of a Web service interface. What I found was that by deserializing from an XmlNodeReader instead of an XmlTextReader, XML Serialization doesn't work...
4
1620
by: Adam Smith | last post by:
XmlValidatingReader too sensitive? I have the following schemas (simplified) and xml file which validate fine in xmlspy, but blow up in xmlvalidatingreader with: 'The 'Hierarchy' element is not declared. An error occurred'. Any help appreciated. To give a brief explanation of what I'm trying to do, the schema 1 is a
4
13786
by: Cheryl Gilbert | last post by:
I'm sending xml to a web service by building a string dynamically. When my web service tries to validate the xml with a schema, I'm getting the error "the root element is missing". If I use an xml file saved to disk, I don't get an error. Does anyone know what the problem could be? - Cheryl Public Function ValidateXML(ByVal sXML As String) As String
9
1942
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as follows (C#): XmlValidatingReader oMyVReader = new XmlValidatingReader(oMyReader); oMyVReader.Schemas.Add(oMySchemaCollection); oMyVReader.ValidationType = ValidationType.Schema;
1
1764
by: Nathan Alden | last post by:
I have an XSD defined as the following: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Application"> <xs:complexType> <xs:sequence> <xs:element name="ReceivedDate" type="xs:string"/> </xs:sequence>
1
2518
by: Borgbjerg | last post by:
I've got a multi-threaded server (we are very early in the project, trying to uncover some risks), and I want to send data using XML. The class ServerAdapter is supposed to connect to the server (which works fine), to send data, but on the same stream be able to read data (which is causing problems). In the function "bool Connect()", we want to instantiate the XmlTextReader with the stream that we got from the 'TcpClient client', but...
1
1312
by: Wolfgang Uhr | last post by:
Hello I have the following problem. I want to use the validating parser XmlValidatingReader and so I write ... FileStream stream = new FileStream(ofd.FileName, FileMode.Open); XmlValidatingReader rdr = new XmlValidatingReader( stream, XmlNodeType.Element, null); rdr.ValidationEventHandler += eventHandler;
1
3224
by: JoeZ | last post by:
Hi all, I have a question about using XMLValidatingReader. I have a schema files (xsd), and a xml data file. In the xml data file, if I don't specify the schema file path, XMLValidatingReader always complains. If schema file path is included, then it doesn't complain. Is there any way to tell XMLValidatingReader where the schema file is, or am
0
10443
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.