ReadXml with a dtd file

A

Amirallia

Hi

Here is my code for loading a XML file into a DataSet

fs = New FileStream("\Program Files\demo.xml", FileMode.Open,
FileAccess.Read)
xr = New XmlTextReader(fs)
ds.ReadXml(xr)

All is ok, but when I load the same XML file with the line <!DOCTYPE
PARENT SYSTEM "demo.dtd">, I have a error( "NotSupportedException")
when I execute ds.ReadXml(xr).

Any idea about this error ?

Thanks
 
I

Ilya Tumanov [MS]

DTDs are not supported on CF. You might be able to fix it by removing DTD
from the file.



However, keep in mind DataSet.ReadXml() is designed to load XML files
created with DataSet.WriteXml().

Loading anything else can fail and/or result in incorrect/unexpected data
loaded.



Best regards,



Ilya



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

Kenneth Windish

Hi,

I was looking at the code you used:

fs = New FileStream("\Program Files\demo.xml", FileMode.Open,
FileAccess.Read)
xr = New XmlTextReader(fs)
ds.ReadXml(xr)

what version of netcf are you using? This does not work for me. This is the
code that is accepted by the editor:

Dim fs = New FileStream("\Program Files\demo.xml", FileMode.Open,
FileAccess.Read)

Dim xr = New Xml.XmlTextReader(fs)


then I get an error about the fs part not being an object and connot convert
object to string or something.

I have written an app. that uses readxml and the results are very slow.
Would like to figure out how to use the xmltextreader, as that it is
reported to be faster.

Thanks in advance for any help.
 
I

Ilya Tumanov [MS]

You should always declare variable types:



Don't:



Dim x


x = 5

Dim xr = New Xml.XmlTextReader(fs)


Do:



Dim x As Int32

x = 5

Dim xr As New Xml.XmlTextReader(fs)


The rule is: Every 'Dim' needs 'As'.



Make sure option 'strict' is turned on for all new projects (in project
properties).

That might be very annoying at first (especially if you just moved from
VB6), but allows to avoid numerous nasty problems VB6 is plagued with.

You'll quickly get used to using CType() to cast objects to whatever type
they supposed to be.



As to using ReadXml(), make sure you have SP3 installed and you have schema
in the DataSet or XML itself.

If you don't have a schema, ReadXml() would have no choice but to use very
slow inference process.

Which is just as bad as not declaring types in VB.



XmlTextReader is a good option and it is faster than even ReadXml() with
schema, but require a lot of work on your part.

It's not going to create an in memory representation of XML.

It works more like VB6 Recordset. But instead of records you're getting XML
elements one by one.



Best regards,



Ilya


Kenneth Windish said:
Hi,

I was looking at the code you used:

fs = New FileStream("\Program Files\demo.xml", FileMode.Open,
FileAccess.Read)
xr = New XmlTextReader(fs)
ds.ReadXml(xr)

what version of netcf are you using? This does not work for me. This is
the
code that is accepted by the editor:

Dim fs = New FileStream("\Program Files\demo.xml", FileMode.Open,
FileAccess.Read)

Dim xr = New Xml.XmlTextReader(fs)


then I get an error about the fs part not being an object and connot
convert
object to string or something.

I have written an app. that uses readxml and the results are very slow.
Would like to figure out how to use the xmltextreader, as that it is
reported to be faster.

Thanks in advance for any help.
 
K

Kenneth Windish

Thanks, that worked.


Ilya Tumanov said:
You should always declare variable types:



Don't:



Dim x


x = 5

Dim xr = New Xml.XmlTextReader(fs)


Do:



Dim x As Int32

x = 5

Dim xr As New Xml.XmlTextReader(fs)


The rule is: Every 'Dim' needs 'As'.



Make sure option 'strict' is turned on for all new projects (in project
properties).

That might be very annoying at first (especially if you just moved from
VB6), but allows to avoid numerous nasty problems VB6 is plagued with.

You'll quickly get used to using CType() to cast objects to whatever type
they supposed to be.



As to using ReadXml(), make sure you have SP3 installed and you have
schema in the DataSet or XML itself.

If you don't have a schema, ReadXml() would have no choice but to use very
slow inference process.

Which is just as bad as not declaring types in VB.



XmlTextReader is a good option and it is faster than even ReadXml() with
schema, but require a lot of work on your part.

It's not going to create an in memory representation of XML.

It works more like VB6 Recordset. But instead of records you're getting
XML elements one by one.



Best regards,



Ilya
 
D

Daniel Moth

FYI, so you don't encounter this problem again, got to your project
properties and turn on Option Strict.

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top