473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XmlDocument persistent errors

I am attempting to parse through an XML document using the XmlDocument
object. I keep getting a NullReferenceException. I have even tried using
the fully qualified name, but with no luck. Here is the code:

private void Page_Load(object sender, System.EventArgs e)
{
StringBuilder sb = new StringBuilder();

System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.Load(Server.MapPath("lib/schoolAnnouncements.xml"));
XmlNode nd;

nd = xd.FirstChild["counties"];

foreach(System.Xml.XmlNode n in nd.ChildNodes)
{
if(n.Name=="county")
sb.Append(String.Format("{0}<br>",n.InnerText));
}

elems=sb.ToString();
}

Any suggestions?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
1 1185
Consider the syntax you used in:

nd = xd.FirstChild["counties"];

Did you mean to use this instead?

nd = xd.SelectNode("counties");

FirstChild is a property of a node, but you're using it as if it were an
indexed collection.

"Philip Townsend" <pt*******@v1tech.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
I am attempting to parse through an XML document using the XmlDocument
object. I keep getting a NullReferenceException. I have even tried using
the fully qualified name, but with no luck. Here is the code:

private void Page_Load(object sender, System.EventArgs e)
{
StringBuilder sb = new StringBuilder();

System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.Load(Server.MapPath("lib/schoolAnnouncements.xml"));
XmlNode nd;

nd = xd.FirstChild["counties"];

foreach(System.Xml.XmlNode n in nd.ChildNodes)
{
if(n.Name=="county")
sb.Append(String.Format("{0}<br>",n.InnerText));
}

elems=sb.ToString();
}

Any suggestions?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
0
by: John Spiegel | last post by:
Hi all, I'm trying to efficiently pull data out of an xml file into a XmlDocument AND create another "sub" document based on one subtree of the document. For example, say I've got: <Books>...
1
by: **** KiteOregon **** | last post by:
I need to send & receive XML Document Objects via the Message Queue. We have several applications that insert XML Document Object into the message queue. This works with no problem. I am trying...
2
by: Eric Zechman via .NET 247 | last post by:
I have a project in which I get xml posted via a hidden form field (data=<xml></xml>). People are entering names like Bill & Sandy Smith. this is coming over as:...
1
by: Chief | last post by:
I am unable to load an xml document that contains Chinese characters in an attribute value. I need to load the document into and XmlDocument object and am using the XmlDocument.Load(string...
4
by: craigkenisston | last post by:
I have an asp.net application in which I sometimes store a persistent cookie once the user has logged in and this has been working great. However, I now add some user information like, username,...
1
by: Pesci Drums | last post by:
Hey There!... I've been dealing for hours trying to figure out why do I get the following error message: Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0,...
3
by: sanchita | last post by:
Hello everyone, I didn't get any response in "Security" forum hence posting here again. I am having problem with persistent cookies. Even after setting "CreatePersistentCookie" to true in...
0
by: dthope69 | last post by:
I have a client that is requiring my web service to accept XMLDocument object as input parameter. I had created it initially to accept byte string and it worked fine. However, when changing to a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.