Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2009, 01:34 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML File Load Issue

I am trying to get an XML document to load so that I can pull information out of it when an aspx page loads and populate labels through out a page.

In the <pagename>.cs.aspx code behind file within the Page_Load function I have the following.

At this point the code initiates; however, it fails at the doc.LoadXML line. I have tried doc.Load and other path attempts with no avail. It jumps to the catch function and rightfully displays the an error has occured.

Could there be a problem in the XML file itself that is causing the error?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Schema;
using System.IO;


public partial class obedience : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 XmlNode node = null;
        try
        {
            XmlDocument doc = new XmlDocument();

           doc.LoadXml("http://www.site.com/XML/Classes.xml");

            node = doc.SelectSingleNode("//class[./name/text()='classname']");

            bodescription.Text = node.ChildNodes[1].InnerText;
    
        }
        catch (Exception ex)
        {
            bodescription.Text = "An Error Occured";
        }
}
}

Last edited by Rollo1002; December 20th, 2009 at 01:39 PM..
 
Old December 20th, 2009, 01:51 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try XmlDocument.Load, rather than XmlDocument.LoadXml.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old December 20th, 2009, 04:43 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That does not work either.

Code:
public partial class obedience : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlNode node = null;
      try
        {
            XmlDocument doc = new XmlDocument();

            doc.Load("http://www.site.com/XML/Classes.xml");

            node = doc.SelectSingleNode("//class[./name/text()='class']");

            bodescription.Text = node.ChildNodes[1].InnerText;
    
        }
        catch (Exception ex)
        {
            bodescription.Text = "An Error Occured";
        }

        

    }

    

}

Last edited by Rollo1002; December 20th, 2009 at 04:44 PM.. Reason: added highlight to change in code
 
Old December 20th, 2009, 06:29 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well I get a 404 for the URL you originally posted (which you've now changed). This should work but without knowing more about any errors you are getting its hard to say what the problem is.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old December 20th, 2009, 07:39 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When I try to access the URI http://www.positivedogtraining.com/XML/PDTSClasses.xml, I get an HTTP error 503 accessing the DTD http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd. This is in principle a transient error indicating that the server is busy, and trying again might succeed. However, it's not a good idea to make your parsing dependent on the W3C server making this DTD available.

The file in question appears to be an XHTML file, and to have nothing in it that would match your XPath expression "//class[./name/text()='Beginning Obedience']".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old December 20th, 2009, 08:04 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The site that I am developing is not live so that's is why the links change and you're getting a 404 error. I am conducting a complete redesign and overhaul.

Here is the error from the output:
'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Users\Laptop\AppData\Local\Temp\Temporary ASP.NET Files\pdtsnew\a294da9d\eea91987\App_Web_nglyac_s.d ll', Symbols loaded.

A first chance exception of type 'System.Xml.XmlException' occurred in System.Xml.dll

Last edited by Rollo1002; December 20th, 2009 at 08:07 PM..
 
Old December 21st, 2009, 01:07 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So I have uploaded this into my test server and still am unable to get it to load. Here is the final code with URL on the test server.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Schema;
using System.IO;





public partial class obedience : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlNode node = null;
      try
        {
            XmlDocument doc = new XmlDocument();


            doc.Load("http://positivedog.urimprovedsite.com/test.xml");

            node = doc.SelectSingleNode("//class[./name/text()='Basic Obedience']");

            bodescription.Text = node.ChildNodes[1].InnerText;
    
        }
        catch (Exception ex)
        {
            bodescription.Text = "An Error Occured";
        }

        

    }

    

}
 
Old December 21st, 2009, 01:24 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Interestingly enough I was able to get it to work; however, I had to remove the try { } catch { } statements from the Page_Load function. Not sure why this is the case if someone knows pass it along.

Thanks for the responses.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access is denied" load a simple xml file nana XML 12 May 12th, 2010 07:01 AM
load XML issue AbrarNazeer XML 5 March 13th, 2008 09:43 AM
How to load an xml file that is in same project? tryston02 C# 2005 1 November 28th, 2006 02:50 PM
Getting VB.NET to load & update XML file kyma XML 0 March 19th, 2005 04:58 PM
LOAD A XML FILE FROM JAVASCRIPT nen Javascript How-To 1 December 20th, 2004 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.