WebException when instantiating XPathDocument

Discussion in 'ASP .Net' started by .NETed, Nov 6, 2009.

  1. .NETed

    .NETed Guest

    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, Nov 6, 2009
    #1
    1. Advertising

  2. .NETed

    .NETed Guest

    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" <> 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, Nov 6, 2009
    #2
    1. Advertising

  3. ".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, Nov 6, 2009
    #3
  4. .NETed

    bruce barker Guest

    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"
    > 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" <> 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, Nov 6, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D
    Replies:
    2
    Views:
    602
  2. srikar

    XPathDocument

    srikar, Oct 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    431
    Guest
    Oct 26, 2003
  3. Keith Chadwick

    Placing dataset into XPathDocument

    Keith Chadwick, Nov 23, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    3,265
    Stephen Cook
    Nov 24, 2003
  4. =?Utf-8?B?U2VhbiBIb2ZmbWFu?=

    Very Slow XSLTransform with XPathDocument

    =?Utf-8?B?U2VhbiBIb2ZmbWFu?=, Nov 18, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    510
    =?Utf-8?B?U2VhbiBIb2ZmbWFu?=
    Nov 18, 2004
  5. ThatsIT.net.au

    RSS, XPathDocument and ISA proxy server

    ThatsIT.net.au, Mar 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    316
    ThatsIT.net.au
    Mar 24, 2007
Loading...

Share This Page