HighTechTalks DotNet Forums  

xmlReader.Create Steam vs InputURI

Dotnet XML microsoft.public.dotnet.xml


Discuss xmlReader.Create Steam vs InputURI in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
SBearss@accessitx.com
 
Posts: n/a

Default xmlReader.Create Steam vs InputURI - 10-15-2007 , 11:55 AM






I'm creating an xmlReader to be used in conjuction with an xml
document to validate schemas.
If I specifiy a FileName in the xmlReader.Create method everything
works as it should
However if I use the fileName and create a FileStream, when I load
the xml document with the reader, I get an error saying that one of
the types in the schema can't be found.
I've tried specifying the baseURI when using a stream but this doesn't
help.
Any ideas on what could be causing this?

(NOTE: GetSchemaSettings is just a method which creates an
XMLReaderSettings object with some flags set)

For example:
Private Function GetSchemaReader(ByVal sXMLData As String, ByVal
oSchema As Stream) As XmlReader Dim oReader As New
StringReader(sXMLData)
Dim oXmlReaderSettings As XmlReaderSettings = GetSchemaSettings()

AddHandler oXmlReaderSettings.ValidationEventHandler, AddressOf
ValidationCallBack

Dim oSchemaReader As XmlReader = XmlReader.Create(oSchema,
oXmlReaderSettings)

oXmlReaderSettings.Schemas.Add(Nothing, oSchemaReader)
oXmlReaderSettings.ValidationType = ValidationType.Schema

Return XmlReader.Create(oReader, oXmlReaderSettings)
End Function


oXMLDoc.Load(GetSchemaReader(sXmlData, oSchema))


Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: xmlReader.Create Steam vs InputURI - 10-15-2007 , 12:10 PM






SBearss (AT) accessitx (DOT) com wrote:
Quote:
I'm creating an xmlReader to be used in conjuction with an xml
document to validate schemas.
If I specifiy a FileName in the xmlReader.Create method everything
works as it should
However if I use the fileName and create a FileStream, when I load
the xml document with the reader, I get an error saying that one of
the types in the schema can't be found.
Does the schema have any xs:include or xs:import elements?

Quote:
I've tried specifying the baseURI when using a stream but this doesn't
help.

Quote:
For example:
Private Function GetSchemaReader(ByVal sXMLData As String, ByVal
oSchema As Stream) As XmlReader Dim oReader As New
StringReader(sXMLData)
Dim oXmlReaderSettings As XmlReaderSettings = GetSchemaSettings()

AddHandler oXmlReaderSettings.ValidationEventHandler, AddressOf
ValidationCallBack

Dim oSchemaReader As XmlReader = XmlReader.Create(oSchema,
oXmlReaderSettings)

oXmlReaderSettings.Schemas.Add(Nothing, oSchemaReader)
oXmlReaderSettings.ValidationType = ValidationType.Schema

Return XmlReader.Create(oReader, oXmlReaderSettings)
End Function


Where do you set a baseURI?
Have you tried supplying an XmlResolver for your XmlReaderSettings?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
SBearss@accessitx.com
 
Posts: n/a

Default Re: xmlReader.Create Steam vs InputURI - 10-15-2007 , 12:23 PM



On Oct 15, 12:10 pm, Martin Honnen <mahotr... (AT) yahoo (DOT) de> wrote:
Quote:
SBea... (AT) accessitx (DOT) com wrote:
I'm creating an xmlReader to be used in conjuction with an xml
document to validate schemas.
If I specifiy a FileName in the xmlReader.Create method everything
works as it should
However if I use the fileName and create a FileStream, when I load
the xml document with the reader, I get an error saying that one of
the types in the schema can't be found.

Does the schema have any xs:include or xs:import elements?





I've tried specifying the baseURI when using a stream but this doesn't
help.
For example:
Private Function GetSchemaReader(ByVal sXMLData As String, ByVal
oSchema As Stream) As XmlReader Dim oReader As New
StringReader(sXMLData)
Dim oXmlReaderSettings As XmlReaderSettings = GetSchemaSettings()

AddHandler oXmlReaderSettings.ValidationEventHandler, AddressOf
ValidationCallBack

Dim oSchemaReader As XmlReader = XmlReader.Create(oSchema,
oXmlReaderSettings)

oXmlReaderSettings.Schemas.Add(Nothing, oSchemaReader)
oXmlReaderSettings.ValidationType = ValidationType.Schema

Return XmlReader.Create(oReader, oXmlReaderSettings)
End Function

Where do you set a baseURI?
Have you tried supplying an XmlResolver for your XmlReaderSettings?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/- Hide quoted text -

- Show quoted text -
Yes, there are several imports. In fact is on one of the elements
refered to by an imports schema that the problem arrises.
No I haven't tried an xmlresolver.



Reply With Quote
  #4  
Old   
Martin Honnen
 
Posts: n/a

Default Re: xmlReader.Create Steam vs InputURI - 10-15-2007 , 12:46 PM



SBearss (AT) accessitx (DOT) com wrote:

Quote:
Yes, there are several imports. In fact is on one of the elements
refered to by an imports schema that the problem arrises.
Do those xs:import elements use relative URLs so that there could be a
problem resolving them?



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #5  
Old   
SBearss@accessitx.com
 
Posts: n/a

Default Re: xmlReader.Create Steam vs InputURI - 10-15-2007 , 01:04 PM



On Oct 15, 12:46 pm, Martin Honnen <mahotr... (AT) yahoo (DOT) de> wrote:
Quote:
SBea... (AT) accessitx (DOT) com wrote:
Yes, there are several imports. In fact is on one of the elements
refered to by an imports schema that the problem arrises.

Do those xs:import elements use relative URLs so that there could be a
problem resolving them?

Yes,
For example, if the original schema file is in
c:\ws\schemas
and is defined like the following
<xs:schema xmlns:ws_tdl="http://www.useit.com/WS_TDL" xmlns:xs="http://
www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/
xmldsig#" xmlns:aix_tdl="http://www.usiet.com/TDL_Interface"
targetNamespace="http://www.useitx.com/WS_TDL"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
xmldsig-core-schema.xsd"/>
<xs:import namespace="http://www.useitx.com/TDL_Interface"
schemaLocation="tdl_interface.xsd"/>
<xs:complexType name="TDLRequest_DateType">


The problem is that the "tdl_interface.xsd" is not being loaded, since
a type defined in this file is not found.

How would I specify to load this? As I said it works using a file name
to load the original but not if it is loaded as a stream.




Reply With Quote
  #6  
Old   
Martin Honnen
 
Posts: n/a

Default Re: xmlReader.Create Steam vs InputURI - 10-16-2007 , 08:52 AM



SBearss (AT) accessitx (DOT) com wrote:

Quote:
<xs:import namespace="http://www.useitx.com/TDL_Interface"
schemaLocation="tdl_interface.xsd"/
<xs:complexType name="TDLRequest_DateType"


The problem is that the "tdl_interface.xsd" is not being loaded, since
a type defined in this file is not found.

How would I specify to load this? As I said it works using a file name
to load the original but not if it is loaded as a stream.
I think you need to specify an XmlResolver on your XmlReaderSettings,
that resolver needs to resolve the relative URLs as needed. One way to
achieve that should be by subclassing XmlUrlResolver and overriding the
ResolveUri method.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.