By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,144 Members | 1,624 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,144 IT Pros & Developers. It's quick & easy.

XmlReader and <xs:import> in schema

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.