Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2007

Tip: Looking for answers? Try searching our database.

XML reader issues....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 17 Apr 2007 01:30 GMT
I have a XML document (not of my making) which starts like that:
==========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
........................
==========

I read it with code such as:
Stream s = .....
using(XmlTextReader xtr = new XmlTextReader(s))
{
   xtr.MoveToContent(); // <<== problem here
   xr.Read();
   .....
}

The problem that I have is, if the user's computer is not connected to a
network, the xtr.MoveToContent() fail with the following exception:
=========
Stack    :
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset
(String systemId, String publicId)
   at
System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter
.PushExternalSubset(String systemId, String publicId)
   at System.Xml.DtdParser.ParseExternalSubset()
   at System.Xml.DtdParser.ParseInDocumentDtd(Boolean
saveInternalSubset)
   at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
   at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlReader.MoveToContent()
-------- Caused by Exception --------
Exception : System.Net.WebException
Message   : Unable to connect to the remote server
Source    : System
Help      :
Stack    :
   at System.Net.HttpWebRequest.GetResponse()
   at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri,
ICredentials credentials)
   at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
credentials)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String
role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.OpenStream(Uri uri)
   at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset
(String systemId, String publicId)

-------- Caused by Exception --------
Exception : System.Net.Sockets.SocketException
Message   : A socket operation was attempted to an unreachable host
Source    : System
Help      :
Stack    :
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress&
address, ConnectSocketState state, IAsyncResult asyncResult, Int32
timeout, Exception& exception)

=========

But I absolutely don't care about the DTD, in fact there is nothing at this
URL.
I try many various settings, but I can't see a way to get around this
problem other than a try/catch.

The problem is: it is easy to forget to put try/catch around the first XML
read.
Is there any better way?
Oleg Tkachenko [MVP] - 17 Apr 2007 07:34 GMT
> I have a XML document (not of my making) which starts like that:
> ==========
[quoted text clipped - 70 lines]
> I try many various settings, but I can't see a way to get around this
> problem other than a try/catch.

XmlReader always checks if DTD exists (to make sure document is
wellformed), it doesn't actually parse it. So the solution is to provide
to XmlReader custom XmlResolver, which will return something dummy when
requested to resolve "http://www.apple.com/DTDs/PropertyList-1.0.dtd".

Signature

Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net

Lloyd Dupont - 17 Apr 2007 08:06 GMT
Thanks Oleg

>> I have a XML document (not of my making) which starts like that:
>> ==========
[quoted text clipped - 75 lines]
> to XmlReader custom XmlResolver, which will return something dummy when
> requested to resolve "http://www.apple.com/DTDs/PropertyList-1.0.dtd".

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.