473,405 Members | 2,261 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,405 software developers and data experts.

Upgrading XMLValidatingReader

Hi all,
As you know, the XMLValidatingReader is deprecated in .NET 2.0. I have the
following snippet from a .NET 1.1 implementation that I am struggling to
upgrade. I know I should use XMLReader.Create, but am struggling to get much
further. Any help would be appreciated. Thanks.

Public Shared Sub ValidateDocument(businessDocument As XmlDocument,
schemaStrongName As String)
' Constants
Const PARTS_IN_SCHEMA_STRONG_NAME As Integer = 2
Const PART_CLASS_NAME As Integer = 0
Const PART_QUALIFIED_ASSEMBLY_NAME As Integer = 1

' Parse schema strong name
Dim assemblyNameParts As String() = schemaStrongName.Split(New Char()
{","c}, PARTS_IN_SCHEMA_STRONG_NAME)
Dim className As String = assemblyNameParts(PART_CLASS_NAME).Trim()
Dim fullyQualifiedAssemblyName As String =
assemblyNameParts(PART_QUALIFIED_ASSEMBLY_NAME).Tr im()

' Load assembly
Dim schemaAssembly As [Assembly] =
[Assembly].Load(fullyQualifiedAssemblyName)

' Create instance of the BTS schema in order to get to the actual schemas
Dim schemaType As Type = schemaAssembly.GetType(className)
Dim btsSchemaCollection As Microsoft.XLANGs.BaseTypes.SchemaBase =
CType(Activator.CreateInstance(schemaType),
Microsoft.XLANGs.BaseTypes.SchemaBase)

' Set up XML validating reader and validate document
Dim parserContext As New XmlParserContext(Nothing, Nothing, "",
XmlSpace.None)
Dim reader As New XmlValidatingReader(businessDocument.OuterXml,
XmlNodeType.Document, parserContext)
reader.ValidationType = ValidationType.Schema
reader.Schemas.Add(btsSchemaCollection.SchemaColle ction)
While reader.Read()
End While
End Sub 'ValidateDocument

--
John
Dec 20 '06 #1
6 5746
A little more info...
This is what I have come up with so far..

' Create instance of the BTS schema in order to get to the actual schemas
Dim schemaType As Type = schemaAssembly.GetType(className)
Dim btsSchemaCollection As Microsoft.XLANGs.BaseTypes.SchemaBase =
CType(Activator.CreateInstance(schemaType),
Microsoft.XLANGs.BaseTypes.SchemaBase)
' Create the XmlSchemaSet class.
Dim sc As New XmlSchemaSet
' Add the schema to the collection.
sc.Add(btsSchemaCollection.Schema)

' Set the validation settings.
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.ValidationType = ValidationType.Schema
settings.Schemas = sc
'AddHandler settings.ValidationEventHandler, AddressOf
ValidationCallBack

' Create the XmlReader object.
Using reader As XmlReader =
XmlReader.Create(businessDocument.SchemaInfo.Schem aAttribute.SchemaType.SourceUri, settings)

' Parse the file.
While reader.Read()
End While

End Using
When I run the app, I get an error that the parameter inputURI was not
recognized as a valid URI. Thus, this is the problem statement.

Using reader As XmlReader =
XmlReader.Create(businessDocument.SchemaInfo.Schem aAttribute.SchemaType.SourceUri, settings)

I have tried all kinds of baseURI, NamespaceURI, SourceURI combos and just
can't seem to get it. So, my very specific question is

How do I specify the inputURI for the document to be validated in creating
the XMLReader? This does NOT work
"businessDocument.SchemaInfo.SchemaAttribute.Schem aType.SourceUri"

Thanks
--
John
"JT" wrote:
Hi all,
As you know, the XMLValidatingReader is deprecated in .NET 2.0. I have the
following snippet from a .NET 1.1 implementation that I am struggling to
upgrade. I know I should use XMLReader.Create, but am struggling to get much
further. Any help would be appreciated. Thanks.

Public Shared Sub ValidateDocument(businessDocument As XmlDocument,
schemaStrongName As String)
' Constants
Const PARTS_IN_SCHEMA_STRONG_NAME As Integer = 2
Const PART_CLASS_NAME As Integer = 0
Const PART_QUALIFIED_ASSEMBLY_NAME As Integer = 1

' Parse schema strong name
Dim assemblyNameParts As String() = schemaStrongName.Split(New Char()
{","c}, PARTS_IN_SCHEMA_STRONG_NAME)
Dim className As String = assemblyNameParts(PART_CLASS_NAME).Trim()
Dim fullyQualifiedAssemblyName As String =
assemblyNameParts(PART_QUALIFIED_ASSEMBLY_NAME).Tr im()

' Load assembly
Dim schemaAssembly As [Assembly] =
[Assembly].Load(fullyQualifiedAssemblyName)

' Create instance of the BTS schema in order to get to the actual schemas
Dim schemaType As Type = schemaAssembly.GetType(className)
Dim btsSchemaCollection As Microsoft.XLANGs.BaseTypes.SchemaBase =
CType(Activator.CreateInstance(schemaType),
Microsoft.XLANGs.BaseTypes.SchemaBase)

' Set up XML validating reader and validate document
Dim parserContext As New XmlParserContext(Nothing, Nothing, "",
XmlSpace.None)
Dim reader As New XmlValidatingReader(businessDocument.OuterXml,
XmlNodeType.Document, parserContext)
reader.ValidationType = ValidationType.Schema
reader.Schemas.Add(btsSchemaCollection.SchemaColle ction)
While reader.Read()
End While
End Sub 'ValidateDocument

--
John
Dec 20 '06 #2
Hi John,

Based on my understanding, you're trying to validate an Xml given an
XmlDocument. If there is any misunderstanding, please feel free to let me
know.

In .NET 2.0, schema validation is supported by XmlDocument, you can use
XmlDocument.Validate to validate it directly. Here is a good example.

http://msdn2.microsoft.com/en-us/library/ms162371.aspx

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Dec 20 '06 #3
Hi John,

The example in the document uses XmlReader.Create because it need to read
from a reader. You can directly load from a file or something else. Here I
wrote an example on my machine and hope it helps.

private void Form1_Load(object sender, EventArgs e)
{
XmlSchema sch = XmlSchema.Read(new
XmlTextReader(@"c:\xmlxsdProblem.xsd"), null);
XmlDocument doc = new XmlDocument();
doc.Schemas.Add(sch);
doc.Load(@"c:\xmlxsdProblem.xml");
ValidationEventHandler a = new
ValidationEventHandler(Validationhandler);
doc.Validate(a);
}

public void Validationhandler(Object sender, ValidationEventArgs e)
{
//....
}

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Dec 21 '06 #4
Thank you very much Kevin.
--
John
"Kevin Yu [MSFT]" wrote:
Hi John,

The example in the document uses XmlReader.Create because it need to read
from a reader. You can directly load from a file or something else. Here I
wrote an example on my machine and hope it helps.

private void Form1_Load(object sender, EventArgs e)
{
XmlSchema sch = XmlSchema.Read(new
XmlTextReader(@"c:\xmlxsdProblem.xsd"), null);
XmlDocument doc = new XmlDocument();
doc.Schemas.Add(sch);
doc.Load(@"c:\xmlxsdProblem.xml");
ValidationEventHandler a = new
ValidationEventHandler(Validationhandler);
doc.Validate(a);
}

public void Validationhandler(Object sender, ValidationEventArgs e)
{
//....
}

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Dec 22 '06 #5
Hi Kevin,

So the alternative is to load the load the entire document into ram?
Is there really no stream based validator in 2.0?

Chuck
Kevin Yu [MSFT] wrote:
Hi John,

The example in the document uses XmlReader.Create because it need to read
from a reader. You can directly load from a file or something else. Here I
wrote an example on my machine and hope it helps.

private void Form1_Load(object sender, EventArgs e)
{
XmlSchema sch = XmlSchema.Read(new
XmlTextReader(@"c:\xmlxsdProblem.xsd"), null);
XmlDocument doc = new XmlDocument();
doc.Schemas.Add(sch);
doc.Load(@"c:\xmlxsdProblem.xml");
ValidationEventHandler a = new
ValidationEventHandler(Validationhandler);
doc.Validate(a);
}

public void Validationhandler(Object sender, ValidationEventArgs e)
{
//....
}

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Dec 24 '06 #6
Hi all,
As you know, the XMLValidatingReader is deprecated in .NET 2.0. I have the
following snippet from a .NET 1.1 implementation that I am struggling to
upgrade. I know I should use XMLReader.Create, but am struggling to get much
further. Any help would be appreciated. Thanks.

Public Shared Sub ValidateDocument(businessDocument As XmlDocument,
schemaStrongName As String)
' Constants
Const PARTS_IN_SCHEMA_STRONG_NAME As Integer = 2
Const PART_CLASS_NAME As Integer = 0
Const PART_QUALIFIED_ASSEMBLY_NAME As Integer = 1

' Parse schema strong name
Dim assemblyNameParts As String() = schemaStrongName.Split(New Char()
{","c}, PARTS_IN_SCHEMA_STRONG_NAME)
Dim className As String = assemblyNameParts(PART_CLASS_NAME).Trim()
Dim fullyQualifiedAssemblyName As String =
assemblyNameParts(PART_QUALIFIED_ASSEMBLY_NAME).Tr im()

' Load assembly
Dim schemaAssembly As [Assembly] =
[Assembly].Load(fullyQualifiedAssemblyName)

' Create instance of the BTS schema in order to get to the actual schemas
Dim schemaType As Type = schemaAssembly.GetType(className)
Dim btsSchemaCollection As Microsoft.XLANGs.BaseTypes.SchemaBase =
CType(Activator.CreateInstance(schemaType),
Microsoft.XLANGs.BaseTypes.SchemaBase)

' Set up XML validating reader and validate document
Dim parserContext As New XmlParserContext(Nothing, Nothing, "",
XmlSpace.None)
Dim reader As New XmlValidatingReader(businessDocument.OuterXml,
XmlNodeType.Document, parserContext)
reader.ValidationType = ValidationType.Schema
reader.Schemas.Add(btsSchemaCollection.SchemaColle ction)
While reader.Read()
End While
End Sub 'ValidateDocument

--
John
I just ran into the same problem you are having and here is the result of my conversion. You can read the article on my blog:
http://www.implementsivillage.net/Pe...9b5502b44.aspx
Let me know if this is helpful!
Christian Loris
http://www.implementsivillage.net

BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities
Jan 15 '07 #7

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

Similar topics

0
by: Larry | last post by:
I believe the .Net XmlValidatingReader should fail when validating XML that contains a ComplexType element with white space when the ComplexType element has the mixed attribute set to false in the...
1
by: Larry | last post by:
Reposting due to lack of response - I believe the .Net XmlValidatingReader should fail when validating XML that contains a ComplexType element with white space when the ComplexType element has the...
18
by: Vlad | last post by:
I have the following code: I have a local copy of the DTD that I need to validate incoming XML documents against. The XML document has the <!DOCTYPE myname SYSTEM "myfile.dtd"> define. When the...
9
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...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
1
by: Bernhard Felkel | last post by:
I have troubles validating XML files with key/keyref constraints. HereĀ“s my schema: <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
1
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST> xml file 2
12
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
1
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...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
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...

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.