Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - WebException when instantiating XPathDocument

 
Thread Tools Search this Thread
Old 11-06-2009, 11:14 AM   #1
Default WebException when instantiating XPathDocument


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?




.NETed
  Reply With Quote
Old 11-06-2009, 11:42 AM   #2
.NETed
 
Posts: n/a
Default Re: WebException when instantiating XPathDocument
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"
xmlnssl="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" <> wrote in message
news:%23m%...
>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?
>
>





.NETed
  Reply With Quote
Old 11-06-2009, 01:56 PM   #3
Gregory A. Beamer
 
Posts: n/a
Default Re: WebException when instantiating XPathDocument
".NETed" <> wrote in
news:#m#:

> 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! |
*******************************************


Gregory A. Beamer
  Reply With Quote
Old 11-06-2009, 02:31 PM   #4
bruce barker
 
Posts: n/a
Default Re: WebException when instantiating XPathDocument
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 wrote:
> 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"
> xmlnssl="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" <> wrote in message
> news:%23m%...
>> 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?
>>
>>

>
>



bruce barker
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46