473,466 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XmlReader and <xs:import> in schema

I am trying to produce a generic "audit report" for
various transactions in our application. Each transaction
type defines a document (and has an associated schema).
When a transaction leads to a "write to the database", we
store the dataset's diffgram in the audit table. To
render the audit report we load the diffgram into a
generic DataSet and bind it to a grid. All works well
unless the document's schema had an <xs:import> to bring
in common GlobalTypes.

The orignal code used an XmlTextReader. I thought that we
could use an XmlValidatingReader and exploit its
XmlSchemaCollection property. In the code below
everything is a local file just to keep the verification
of the concept simple. But the wheels seem to fall off
when I used the XmlValidatingReader. For XML files without
<import>s the resulting DataSet object, dsResults, is
Nothing. For files with <import>s deserialization fails
with a schema error (types defined in the import are not
being found -- suggesting that the schema cache does
nothing for the <import>)

Note that experiments have shown xsc.Add() is finding the
refernced schema (misname the file or put an error in the
file and Add() throws an exception). I later desparately
threw in the XmlUriResolver, to no effect.

Any suggestions?
dsResults.Clear()
' A FileStream is needed to read the XML document.
Dim filename As String = "SmfDg.xml"
Dim fs As New FileStream(filename, FileMode.Open)
Dim xtr As New XmlTextReader(fs)
Try
Dim vxtr As XmlValidatingReader = New
XmlValidatingReader(xtr)
vxtr.ValidationType = ValidationType.None
Dim xsc As New XmlSchemaCollection
xsc.Add
("http://vanguard.com/fima2/TransactionTypes.xsd", "C:\\Fim
a2\\Solutions\\Projects\\Common\\DataSets\\Transac tions\\"
& "TransactionTypes.xsd")
xsc.Add
("http://vanguard.com/fima2/SmfDataSet.xsd", "C:\\Fima2
\\Solutions\\Projects\\Common\\DataSets\\Smf\\"
& "SMFDataSet.xsd")
vxtr.Schemas.Add(xsc)

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

dgAuditDetail.DataSource = dsResults
dgAuditDetail.DataMember = dsResults.Tables
(0).TableName

Catch ex As Exception
Trace.WriteLine(ex.ToString)
Finally
fs.Close()
End Try
Nov 12 '05 #1
1 2663
Ed,

you don't show the XSD file here. Since you say that the .xsd files are
being found successfully, maybe it's in the schemas themselves that they
can't resolve namespaces...

"Ed Bacon" <Ed********@vanguard.com> wrote in message
news:d4****************************@phx.gbl...
I am trying to produce a generic "audit report" for
various transactions in our application. Each transaction
type defines a document (and has an associated schema).
When a transaction leads to a "write to the database", we
store the dataset's diffgram in the audit table. To
render the audit report we load the diffgram into a
generic DataSet and bind it to a grid. All works well
unless the document's schema had an <xs:import> to bring
in common GlobalTypes.

The orignal code used an XmlTextReader. I thought that we
could use an XmlValidatingReader and exploit its
XmlSchemaCollection property. In the code below
everything is a local file just to keep the verification
of the concept simple. But the wheels seem to fall off
when I used the XmlValidatingReader. For XML files without
<import>s the resulting DataSet object, dsResults, is
Nothing. For files with <import>s deserialization fails
with a schema error (types defined in the import are not
being found -- suggesting that the schema cache does
nothing for the <import>)

Note that experiments have shown xsc.Add() is finding the
refernced schema (misname the file or put an error in the
file and Add() throws an exception). I later desparately
threw in the XmlUriResolver, to no effect.

Any suggestions?
dsResults.Clear()
' A FileStream is needed to read the XML document.
Dim filename As String = "SmfDg.xml"
Dim fs As New FileStream(filename, FileMode.Open)
Dim xtr As New XmlTextReader(fs)
Try
Dim vxtr As XmlValidatingReader = New
XmlValidatingReader(xtr)
vxtr.ValidationType = ValidationType.None
Dim xsc As New XmlSchemaCollection
xsc.Add
("http://vanguard.com/fima2/TransactionTypes.xsd", "C:\\Fim
a2\\Solutions\\Projects\\Common\\DataSets\\Transac tions\\"
& "TransactionTypes.xsd")
xsc.Add
("http://vanguard.com/fima2/SmfDataSet.xsd", "C:\\Fima2
\\Solutions\\Projects\\Common\\DataSets\\Smf\\"
& "SMFDataSet.xsd")
vxtr.Schemas.Add(xsc)

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

dgAuditDetail.DataSource = dsResults
dgAuditDetail.DataMember = dsResults.Tables
(0).TableName

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

Nov 12 '05 #2

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

Similar topics

1
by: Bernd Oninger | last post by:
As far as I know one could use other xsd schemas with the import and the xlink feature. What are the differences (beside the syntax)? Bernd
6
by: PA | last post by:
My dream XML will look like as follows: <?xml version="1.0"?> <bk:bookList xmlns:bk="urn:BookSampleSchema.xdr"> <book> <title>Doe's Book</title> <author>J Doe</author> <year>2002</year>...
0
by: Rupa | last post by:
Hi, Can anyone tell me how to eliminate the import tags from an XSD? I want to be able to take this XSD into a Dataset using the ReadXMLSchema method of a XMLDataDocument. Currently this fails...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
2
by: MarkAurit | last post by:
How does one go about getting the information from an .xsd file into a WSDL document? I have a web service that creates a simple object that IBM Websphere can see and use. Great. However, when I...
5
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in...
3
by: sachinvyas | last post by:
Hi, I have following schema saved in new.xsd <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://www.smpte-ra.org/schemas/429.7/2006/CPL"...
2
by: Darrell Plank | last post by:
I'm a real XML novice, but my ultimate goal here is to get a workable schema for the GEDCOM XML format as spec'ed out here: http://www.familysearch.org/GEDCOM/GedXML60.pdf It's a proposed XML...
4
by: IsValidUN | last post by:
I have an XSD which has an import to an XSD located on the web which has a DTD within it. (Using VS-2005 2.0 framework) If I load the XSD using the following, it can't find elements defined within...
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
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
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.