473,386 Members | 1,706 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.

SelectSingleNode not working

I'm trying to invoke the "selectsinglenode" method on an XmlDocument object,
but it doesn't seem able to find the node I want. I'm able to access the
document root but when I try to parse an invividual node, I get an
"System.NullReferenceException: Object reference not set to an instance of an
object." exception when I try to response.write the value. I don't know if
it's an xpath issue or a .net issue, but I could really use a helping hand
here. XML & code follow:

objBatchDataDoc = New XmlDocument
objBatchDataDoc.Load("http://localhost/ReportData.xml")
objAgreementNode =
objBatchDataDoc.selectsinglenode("//job/batch/agreement[@agreementnumber='5022883004']")

'ERROR OCCURS HERE
response.write(objAgreementNode.innerText)

-------------------------------------------------------------------------

<job xmlns="http://www.w3schools.com">
<batch batchid="7465">
<agreement agreementnumber="5022883004">
<coveragestartdate>8/3/2005</coveragestartdate>
<coverageenddate>3/19/2007</coverageenddate>
<partnumber>RSCU-10-4LP</partnumber>
<agreementcharge>45.02</agreementcharge>
<distributornumber>A90394</distributornumber>
<ownerfirstname>glenn</ownerfirstname>
<ownerlastname>venzke</ownerlastname>
<ownerphonenumber>(630) 455-1435</ownerphonenumber>
<owneraddress>16 kingery quarter drive, unit 4A</owneraddress>
<ownercity>willowbrook</ownercity>
<ownerstate>IL</ownerstate>
<ownerzipcode>60530</ownerzipcode>
<salesrepfirstname>jeff</salesrepfirstname>
<salesreplastname>liter</salesreplastname>
<contractornumber>47822AA</contractornumber>
<brandedprogramcode>190</brandedprogramcode>
<companyname>equiguard</companyname>
<companyphonenumber>(630) 971-9705</companyphonenumber>
<companyaddress>800 jorie blvd</companyaddress>
<companycity>oakbrook</companycity>
<companystate>FL</companystate>
<companyzipcode>60523</companyzipcode>
<equipmenttype>residential</equipmenttype>
<equipmentdescription>
<![CDATA[Residential/Commercial: RESIDENTIAL COMPLETE SYSTEM OR PACKAGE
UNIT WITH THERMOSTAT (FURNACE / AIR CONDITIONER OR HEAT PUMP AND EVAPORATOR
COIL) UP TO AND INCLUDING 5 TON
Equipment Type: COMPLETE SYSTEM OR PACKAGE UNIT
Term: 1826 Days | 60 Months | 5.00 Years
Coverage: LABOR AND MARKUP ONLY
Start: 2ND YEAR
Size: <= 5 TON ]]>
</equipmentdescription>
<equipment>
<manufacturer>Heil</manufacturer>
<equipmenttype>Water Heater</equipmenttype>
<modelnumber>58HWC243A</modelnumber>
<serialnumber>S8403J10199</serialnumber>
<unitsize>4600 BTU</unitsize>
<installationdate>7/11/2005</installationdate>
</equipment>
</agreement>
</batch>
</job>
Oct 14 '05 #1
1 2185
try this...

XmlDocument objBatchDataDoc = new XmlDocument();

XmlNamespaceManager nsmgr = new XmlNamespaceManage(objBatchDataDoc.NameTable
);
nsmgr.AddNamespace( "ns", "http://www.w3schools.com" );
string myxml = getXML();

objBatchDataDoc.LoadXml(myxml);
XmlNode objAgreementNode =
objBatchDataDoc.SelectSingleNode("//ns:agreement[@agreementnumber='5022883004']", nsmgr);

//ERROR OCCURS HERE
MessageBox.Show(objAgreementNode.InnerText);

"Glenn Venzke" wrote:
I'm trying to invoke the "selectsinglenode" method on an XmlDocument object,
but it doesn't seem able to find the node I want. I'm able to access the
document root but when I try to parse an invividual node, I get an
"System.NullReferenceException: Object reference not set to an instance of an
object." exception when I try to response.write the value. I don't know if
it's an xpath issue or a .net issue, but I could really use a helping hand
here. XML & code follow:

objBatchDataDoc = New XmlDocument
objBatchDataDoc.Load("http://localhost/ReportData.xml")
objAgreementNode =
objBatchDataDoc.selectsinglenode("//job/batch/agreement[@agreementnumber='5022883004']")

'ERROR OCCURS HERE
response.write(objAgreementNode.innerText)

-------------------------------------------------------------------------

<job xmlns="http://www.w3schools.com">
<batch batchid="7465">
<agreement agreementnumber="5022883004">
<coveragestartdate>8/3/2005</coveragestartdate>
<coverageenddate>3/19/2007</coverageenddate>
<partnumber>RSCU-10-4LP</partnumber>
<agreementcharge>45.02</agreementcharge>
<distributornumber>A90394</distributornumber>
<ownerfirstname>glenn</ownerfirstname>
<ownerlastname>venzke</ownerlastname>
<ownerphonenumber>(630) 455-1435</ownerphonenumber>
<owneraddress>16 kingery quarter drive, unit 4A</owneraddress>
<ownercity>willowbrook</ownercity>
<ownerstate>IL</ownerstate>
<ownerzipcode>60530</ownerzipcode>
<salesrepfirstname>jeff</salesrepfirstname>
<salesreplastname>liter</salesreplastname>
<contractornumber>47822AA</contractornumber>
<brandedprogramcode>190</brandedprogramcode>
<companyname>equiguard</companyname>
<companyphonenumber>(630) 971-9705</companyphonenumber>
<companyaddress>800 jorie blvd</companyaddress>
<companycity>oakbrook</companycity>
<companystate>FL</companystate>
<companyzipcode>60523</companyzipcode>
<equipmenttype>residential</equipmenttype>
<equipmentdescription>
<![CDATA[Residential/Commercial: RESIDENTIAL COMPLETE SYSTEM OR PACKAGE
UNIT WITH THERMOSTAT (FURNACE / AIR CONDITIONER OR HEAT PUMP AND EVAPORATOR
COIL) UP TO AND INCLUDING 5 TON
Equipment Type: COMPLETE SYSTEM OR PACKAGE UNIT
Term: 1826 Days | 60 Months | 5.00 Years
Coverage: LABOR AND MARKUP ONLY
Start: 2ND YEAR
Size: <= 5 TON ]]>
</equipmentdescription>
<equipment>
<manufacturer>Heil</manufacturer>
<equipmenttype>Water Heater</equipmenttype>
<modelnumber>58HWC243A</modelnumber>
<serialnumber>S8403J10199</serialnumber>
<unitsize>4600 BTU</unitsize>
<installationdate>7/11/2005</installationdate>
</equipment>
</agreement>
</batch>
</job>

Oct 14 '05 #2

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

Similar topics

3
by: John R. | last post by:
I have an application written in C# and i am using MS XML DOM! I have a document with the following structure (only the <DicEntry> - Elements are important): <NewDataSet...
2
by: Edward Yang | last post by:
My XML document has a default namespace specified by xmlns="some_url". Here it is: <?xml version="1.0" encoding="utf-8" ?> <ssmproject name="sample" server="sql"...
7
by: Jason | last post by:
Hi I have an XML file i need to load and read the contents. Here is the top part of the xml file. <Research xsi:schemaLocation="http://www.rixml.org/2002/6/RIXML...
2
by: smita | last post by:
Hi, I have an Xml file in which i am storing the usernames and password and some other user details. The file contains data as shown below.. <?xml version="1.0" encoding="utf-8"?> <RoleTables...
6
by: Jay Bienvenu | last post by:
I have the following Visual Basic .NET code in an ASP.NET project: ' ... Dim xdStructure As XmlDocument Dim xnStructureRoot As XmlNode xdStructure = New XmlDocument...
2
by: adam | last post by:
I tried so many ways to select the node but its not working, please help. I want to research by the identifier in imsmanifest.xml file, the node could be item or resource. XmlDocument doc = new...
7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
1
by: Glenn Venzke | last post by:
I'm trying to invoke the "selectsinglenode" method on an XmlDocument object, but it doesn't seem able to find the node I want. I'm able to access the document root but when I try to parse an...
0
by: compumate99 | last post by:
I am trying to parse the xml document using selectsinglenode method. I am doing this using Visual Foxpro >>> loResultXml = CreateObject("Microsoft.XMLDOM") With loResultXml .Async = .F. ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.