NotSupportedExeception on XmlTextReader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Would anybody advise on the following code why it did run correctly in
Windows XP but did not run correctly in Windows Mobile ?

I am writing a C# program on Window Mobile 5.0 device to parse the content
of a XML file but exception raised when the program started.

The content of the XML file is:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

<MessageCenter>
&message-center-connection;

<other-settings>
.........
</other-settings>
</MessageCenter>

The contain of the MessageCenterConnection.xml is
<connection>
<host>localhost</host>
<port>3550</port>
</connection>

The C# code used to parse the XML is:
protected XmlDocument xmlDoc = null;

xmlDoc = new XmlDocument();
try
{
XmlTextReader xmlTextReader = new XmlTextReader(xmlConfig);
xmlTextReader.EntityHandling = EntityHandling.ExpandEntities;
xmlDoc.Load(xmlTextReader);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

when the program was run under Windows Mobile, the following message was
displayed:

System.NotSupportedException: NotSupportedException
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode()
at System.Xml.XmlLoader.LoadDocSequence()
at System.Xml.XmlLoader.Load()
at System.Xml.XmlDocument.Load()
at
Symbol.Application.Framework.Configuration.ConfigTemplate.LoadConfigSettings()
at Symbol.MessageCenter.ConfigMessageCenter.ReadConfigFromXML()
at Symbol.MessageCenter.ConfigMessageCenter..ctor()
at Symbol.MessageCenter.Configuration..ctor()
at Symbol.MessageCenter.MessageCenter..ctor()
at Symbol.MessageCenter.Program.Main()

If I removed the
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

and

&message-center-connection;

from the XML, the program run correctly in WM5.0.
 
The Compact Framework does not support inline DTDs in your XML documents.
Thats why it works when you remove it.

Peter
 
Hi Peter

I found that most of the methods related to DTD validating / entity
resolving are
marked as "Supported by .NET CF". Is there any easy way to know which methods
are real supported in implementation ?

Peter Foot said:
The Compact Framework does not support inline DTDs in your XML documents.
Thats why it works when you remove it.

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

Antony said:
Would anybody advise on the following code why it did run correctly in
Windows XP but did not run correctly in Windows Mobile ?

I am writing a C# program on Window Mobile 5.0 device to parse the content
of a XML file but exception raised when the program started.

The content of the XML file is:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

<MessageCenter>
&message-center-connection;

<other-settings>
.........
</other-settings>
</MessageCenter>

The contain of the MessageCenterConnection.xml is
<connection>
<host>localhost</host>
<port>3550</port>
</connection>

The C# code used to parse the XML is:
protected XmlDocument xmlDoc = null;

xmlDoc = new XmlDocument();
try
{
XmlTextReader xmlTextReader = new XmlTextReader(xmlConfig);
xmlTextReader.EntityHandling = EntityHandling.ExpandEntities;
xmlDoc.Load(xmlTextReader);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

when the program was run under Windows Mobile, the following message was
displayed:

System.NotSupportedException: NotSupportedException
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode()
at System.Xml.XmlLoader.LoadDocSequence()
at System.Xml.XmlLoader.Load()
at System.Xml.XmlDocument.Load()
at
Symbol.Application.Framework.Configuration.ConfigTemplate.LoadConfigSettings()
at Symbol.MessageCenter.ConfigMessageCenter.ReadConfigFromXML()
at Symbol.MessageCenter.ConfigMessageCenter..ctor()
at Symbol.MessageCenter.Configuration..ctor()
at Symbol.MessageCenter.MessageCenter..ctor()
at Symbol.MessageCenter.Program.Main()

If I removed the
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

and

&message-center-connection;

from the XML, the program run correctly in WM5.0.
 
There is a discussion of what is supported in System.Xml in .NETCF v2.0
here:-
http://blogs.msdn.com/ihimmar/archive/2004/04/27/120837.aspx
http://blogs.msdn.com/ihimmar/archive/2004/05/05/126245.aspx
https://blogs.msdn.com/ihimmar/archive/2004/05/14/132193.aspx

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

Antony said:
Hi Peter

I found that most of the methods related to DTD validating / entity
resolving are
marked as "Supported by .NET CF". Is there any easy way to know which
methods
are real supported in implementation ?

Peter Foot said:
The Compact Framework does not support inline DTDs in your XML documents.
Thats why it works when you remove it.

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

Antony said:
Would anybody advise on the following code why it did run correctly in
Windows XP but did not run correctly in Windows Mobile ?

I am writing a C# program on Window Mobile 5.0 device to parse the
content
of a XML file but exception raised when the program started.

The content of the XML file is:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

<MessageCenter>
&message-center-connection;

<other-settings>
.........
</other-settings>
</MessageCenter>

The contain of the MessageCenterConnection.xml is
<connection>
<host>localhost</host>
<port>3550</port>
</connection>

The C# code used to parse the XML is:
protected XmlDocument xmlDoc = null;

xmlDoc = new XmlDocument();
try
{
XmlTextReader xmlTextReader = new XmlTextReader(xmlConfig);
xmlTextReader.EntityHandling = EntityHandling.ExpandEntities;
xmlDoc.Load(xmlTextReader);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

when the program was run under Windows Mobile, the following message
was
displayed:

System.NotSupportedException: NotSupportedException
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode()
at System.Xml.XmlLoader.LoadDocSequence()
at System.Xml.XmlLoader.Load()
at System.Xml.XmlDocument.Load()
at
Symbol.Application.Framework.Configuration.ConfigTemplate.LoadConfigSettings()
at Symbol.MessageCenter.ConfigMessageCenter.ReadConfigFromXML()
at Symbol.MessageCenter.ConfigMessageCenter..ctor()
at Symbol.MessageCenter.Configuration..ctor()
at Symbol.MessageCenter.MessageCenter..ctor()
at Symbol.MessageCenter.Program.Main()

If I removed the
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

and

&message-center-connection;

from the XML, the program run correctly in WM5.0.
 
Antony said:
:
I found that most of the methods related to DTD validating / entity
resolving are
marked as "Supported by .NET CF". Is there any easy way to know which
methods
are real supported in implementation ?
[/QUOTE]
In fact it is apparently /any/ instance of the DOCTYPE element in a XML
document, even just where is a reference to an external file e.g.
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd"> It would
be much better if it would just ignore such elements -- just not loading
the referenced file. I can see that it might be harder to support the
case where a "internal subset" is included e.g. <!DOCTYPE folder-listing
SYSTEM "obex-folder-listing.dtd"
[ <!ATTLIST folder mem-type CDATA #IMPLIED>
There's OBEX library called Brecham.Obex, available from Peter's
http://www.32feet.net site. It provide support for all OBEX (Object
transfer protocol) features. The developer of it encountered this
limitation. Quoting from its readme:

"The Folder Listing parser failed on the NETCF when reading listings
from most peer devices. This is due to a lack of support for DTDs in
the NETCF XmlTextReader class, if used on a document that contains a
DOCTYPE element it throws a NotSupportedException. This is bad, as the
Folder Listing document is defined in the OBEX specification by a DTD
and all the documents I've see do contain the document type declaration.
This has been worked-around by creating code to strip any DOCTYPE
element from received documents."

So Andy (the developer of Brecham.Obex) has managed to strip both types
of DOCTYPE element...

The code that does the DOCTYPE stripping could be used by external
applications. It is present in the library but is hidden from
IntelliSense and doesn't appear in the documentation, but can be found
as class Brecham.Obex.Objects.XmlDocTypeStripperStream. Just wrap it
round your source stream -- assuming variable 'xmlConfig' in your
original post is a stream. e.g. change your code to be:
XmlDocTypeStripperStream strm = new
XmlDocTypeStripperStream(xmlConfig)
XmlTextReader xmlTextReader = new XmlTextReader(strm);

Would anybody advise on the following code why it did run
correctly in Windows XP but did not run correctly in Windows
Mobile ? I am writing a C# program on Window Mobile 5.0 device to
parse the
content
of a XML file but exception raised when the program started.

The content of the XML file is:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

<MessageCenter>
&message-center-connection;

<other-settings>
.........
</other-settings>
</MessageCenter>

The contain of the MessageCenterConnection.xml is
<connection>
<host>localhost</host>
<port>3550</port>
</connection>

The C# code used to parse the XML is:
protected XmlDocument xmlDoc = null;

xmlDoc = new XmlDocument();
try
{
XmlTextReader xmlTextReader = new XmlTextReader(xmlConfig);
xmlTextReader.EntityHandling = EntityHandling.ExpandEntities;
xmlDoc.Load(xmlTextReader);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

when the program was run under Windows Mobile, the following
message was
displayed:

System.NotSupportedException: NotSupportedException
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode()
at System.Xml.XmlLoader.LoadDocSequence()
at System.Xml.XmlLoader.Load()
at System.Xml.XmlDocument.Load()
at
Symbol.Application.Framework.Configuration.ConfigTemplate.LoadConfigSettings()
at Symbol.MessageCenter.ConfigMessageCenter.ReadConfigFromXML()
at Symbol.MessageCenter.ConfigMessageCenter..ctor()
at Symbol.MessageCenter.Configuration..ctor()
at Symbol.MessageCenter.MessageCenter..ctor()
at Symbol.MessageCenter.Program.Main()

If I removed the
<!DOCTYPE MessageCenter [
<!ENTITY message-center-connection SYSTEM
"MessageCenterConnection.xml"?>
]?>

and

&message-center-connection;

from the XML, the program run correctly in WM5.0.
 
Back
Top