WebException when instantiating XPathDocument

  • Thread starter Thread starter .NETed
  • Start date Start date
N

.NETed

I am experiencing a strange problem. In my page I do the following:

public string Transform(string xmlfile, string xsltfile)
{
if (xmlfile != null && xsltfile != null)
{
XPathDocument xpathdoc = new XPathDocument(xmlfile);
:
}
}

other code has been left out. I always get a "WebException was unhandled by
user code" and the message of the web exception is "The remote server
returned an error: (503) Server Unavailable."

I am not retrieving the file (XSL or XML) from any remote server, in fact
the file is local. When I debug I see the exception is thrown during the
instantiation of XPathDocument where the xmlfile parameter value is
"D:\Websites\MySite\backend\xmlsource.htm" (I changed the name for the
purpose of this post).

The path and file in the value of the variable DOES exist. So why am I
getting a WebException? The file is simply an HTML snippet (not a whole HTML
document) without any weird or foreign characters (only ASCII characters).

Any ideas what is wrong there?
 
A correction, the xmlfile points to a full HTML source file with DOCTYPE and
HTML root element. I have not come up with a solution yet.

The XSL document that transforms the HTML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY lquot "«">
<!ENTITY rquot "»">
<!ENTITY ntilde "ñ">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/html/body">
<xsl:apply-templates />

</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
 
I am not retrieving the file (XSL or XML) from any remote server, in
fact the file is local. When I debug I see the exception is thrown
during the instantiation of XPathDocument where the xmlfile parameter
value is "D:\Websites\MySite\backend\xmlsource.htm" (I changed the
name for the purpose of this post).

Try loading the doc as an XML document first and make sure you are not
having a problem resolving the path.

The only other thing I can think of is the absolute drive path is
causing issues. In general, the linked XML files I have used have been
URLs, not drive paths. This is true of schemas, docs, etc. Not sure it
should or would make a difference, but if the doc can resolve as a doc,
then it is the link that is the problem.

Peace and Grace,
Greg

--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
in general html is not valid xml and will throw errors when loaded as
xml. you can run you html file through a validator:

http://validator.w3.org/

-- bruce (sqlwork.com)

..NETed said:
A correction, the xmlfile points to a full HTML source file with DOCTYPE and
HTML root element. I have not come up with a solution yet.

The XSL document that transforms the HTML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY lquot "«">
<!ENTITY rquot "»">
<!ENTITY ntilde "ñ">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/html/body">
<xsl:apply-templates />

</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


.NETed said:
I am experiencing a strange problem. In my page I do the following:

public string Transform(string xmlfile, string xsltfile)
{
if (xmlfile != null && xsltfile != null)
{
XPathDocument xpathdoc = new XPathDocument(xmlfile);
:
}
}

other code has been left out. I always get a "WebException was unhandled
by user code" and the message of the web exception is "The remote server
returned an error: (503) Server Unavailable."

I am not retrieving the file (XSL or XML) from any remote server, in fact
the file is local. When I debug I see the exception is thrown during the
instantiation of XPathDocument where the xmlfile parameter value is
"D:\Websites\MySite\backend\xmlsource.htm" (I changed the name for the
purpose of this post).

The path and file in the value of the variable DOES exist. So why am I
getting a WebException? The file is simply an HTML snippet (not a whole
HTML document) without any weird or foreign characters (only ASCII
characters).

Any ideas what is wrong there?
 
Back
Top