How to deal with empty element using ReadXML

below is a very simple XML file.
I use ReadXml to read data.
When it reaches an empty element as  <Product />  below, my program crashes.
The error:
System.NullReferenceException: Object reference not set to an instance of an 
object.

How can I assign a value to this empty element?

Thanks

Bill

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

- <Inventory Type="Physical">
  <Product />
  <TankNumber>0031022207-1</TankNumber>
  <UserDefinedTag>0</UserDefinedTag>
  <DateTime>2007-07-11T03:52:00</DateTime>
  <Volume>0</Volume>
  <Ullage>1005</Ullage>
  <Height>0</Height>
  <WaterHeight>0</WaterHeight>
  <DaystoEmpty>0</DaystoEmpty>
  </Inventory> 


0
7/12/2007 8:41:59 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
830 Views

Similar Articles

[PageSpeed] 14

* Bill Nguyen wrote in microsoft.public.dotnet.xml:
>below is a very simple XML file.
>I use ReadXml to read data.
>When it reaches an empty element as  <Product />  below, my program crashes.
>The error:
>System.NullReferenceException: Object reference not set to an instance of an 
>object.
>
>How can I assign a value to this empty element?

That would be the wrong solution for the problem. You have to rewrite
your code so that the exception does not occur. Some part of your code
assumes all elements (or the Product element specifically) have some
children, you need to remove that assumption.
-- 
Bj�rn H�hrmann � mailto:bjoern@hoehrmann.de � http://bjoern.hoehrmann.de
Weinh. Str. 22 � Telefon: +49(0)621/4309674 � http://www.bjoernsworld.de
68309 Mannheim � PGP Pub. KeyID: 0xA4357E78 � http://www.websitedev.de/ 
0
bjoern1 (135)
7/12/2007 10:35:49 PM
Reply:

Similar Artilces:

Posted using incorrect exchange rate
We originally posted transactions in January 2006 with the incorrect exchange rate. What would be the simplest way to fix our mistake in May 2006? ...

Using icon sets with relative references
I am using Excel 2007 in the Vista OS. I am trying to use conditional formatting with an icon set in a column but Excel will not allow relative references. Example: A1=10 min B1=20 max C1=30 oh D1=a formula { =IF(C1=0,B1,(B1-C1)) } The condtional formatting of D1 would be: if the value showing in D1 is >B1 the cell would show a red 'X', if the value showing in D1 is <A1 the cell would show a green 'check mark', and if the value showing in D1 is between the values in A1 and B1 it would show a yellow 'exclamation point'. I can get the D1 ...

Completing the activity using custom .net code
Hello, Depending upon certain conditions in a custom code i want to complete the task activity which should then be visible in History link of CRM. Can anyone give me the sample code for the same. protected void Button1_Click(object sender, System.EventArgs e) { CrmService service=new CrmService(); service.Url=ConfigurationSettings.AppSettings["Url"]; service.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["CredentialsUName"],ConfigurationSettings.AppSettings["CredentialsPwd"],ConfigurationSettings.AppSettings["Cred...

RMS Add-Ins: managing state using session variables
Hi, I'm new to the world of RMS, but have been looking into making RMS Add- Ins. I'm developing in C#. I've got a couple of add-ins written that don't do anything particular at the moment, but do need a way of passing state to each other. The two add-ins are hooked into the InitializeTransaction and PrintReceipt hooks. At the moment, I'm passing state around by using a session variable. However, what I find a little odd is that the session variables appear to be implemented as a fixed 10-position array. For my initial testing I'm just arbitrarily picking one slot in...

Using DCount with WHERE criteria
My main form holds patient information (tblPatients), and my subform holds daily information (tblDailyData) collected for each patient. (Hence, a one-to-many.) An individual patient should not have the same date entered twice, so on the subform, in the BeforeUpdate event of the date control, I need to check for a duplicate date. Right now my code looks like: If DCount("DailyDate", "tblDailyData", "DailyDate= #" & Me.DailyDate & "#") > 0 Then Me.Undo MsgBox "Sorry! This date has already been entered.", vbExclamation, "...

Message problems after using the Inbox Repair Tool
In Outlook 2000 I ran the Inbox Repair Tool on a damaged pst file. It repaired the file but now I can't move/copy many of the e-mails from the "Recovered Folder". I get the error message: "Can't copy the items. This task cannot be performed for Remote Mail message headers. Download the complete messages, and then complete the task" However, the message is complete and I can read it by opening the message as normal. Also the preview pane doesn't work on these messages - I get a message saying: "This item contains active content that cannot be dis...

Use Tab Name as Value
What I want to do is have the worksheet tab name translate to appropiate row on the ChartsData worksheet dynamically instead of me having to place a huge bunch of mods for each chart number, (right now I'm up to 132). Worksheet Names: Sheet 1 == Chart0001 Sheet 2 == Chart0002 etc... =OFFSET(ChartsData!ChartStatTitles,1,0) ChartsData!ChartStatTitles == "=ChartsData!$B$1:$G$1" Cell A1 == "Chart #s" $A$2 == Chart0001 $A$3 == Chart0002 etc... I was thinking of something like "indirect" but I can't seem to quite...

A field on a query has a value in it I'd like to use to create tot
Cost: Proceeds: G/L St G/L LT 30,000 31,000 $1,000 25,100 24,095 ($905) 4,000 5,000 $500 $500 In the G/L St & G/L Lt field, I would like to pull out the cost/proceeds values to create a field that I can run a cost or proceed total on. I have done an IIf function that works in pulling out the values but in the report footer when I try to sum the data, it doesn't work. FYI: The iif function is this: Iif([g/l s...

using queue for incoming e-mail
I have created queue and want it to get all e-mail from support@xyd.com i tried but i can not find any way to do it , any solution . ...

Analyzing Results of a Survey Using Option Buttons
I have a bunch of scenarios, for each scenario I ask a number of questions, each question has 3 options (using option buttons) "Yes", "No", "Maybe"; It's a survey, and I will have a number of surveys coming back and need to summarize the results. Spreadsheet Looks Something Like: Column A Column B Column C Column D Column E... Scenario1 Answer Question1 Question2 Question 3... Yes Option Button Option Button No Option Button Option Button ...

Using same SSRS installation to support two different CRM installs
We are implementing a second instance of CRM 4.0. It is for a different business so CRM will be installed on a different server than our current instance. Multihoming is not an option. In our current implementation our Reporting Services installation is on a different box than CRM. We would like to use the same SSRS server for reports for the new CRM installation. Is this possible? Our Reporting SErvices server is on a different machine also. -- Leo That should work just fine aslong as the organization names are different. Otherwise both instances will try to use the same folder...

Keeping leading zeros when using Text-to-Columns
Hi all, I'm using Excel X for Mac, and I'm trying to split my four-digit dat into two rows with two digits each: 0001 => 00|01 0101 => 01|01 9800 => 98|00 When I first imported the data it dropped all the leading zeros, bu this was quickly remedied by making the custom format: 0000 However, if I go straight from here to text-to-columns the zeros don' show up in the fixed-width option screen, making it impossible t properly separate them. Likewise, if I try to set the formatting of the cells to text, all th leading zeros are instantly dropped. The latter attempt - swi...

Using HYPERLINK Function in array formula
I've spent a good part of the day working on a few pretty complex array formulas. I'd now like to add one that will create an array of hyperlinks. I thought I could do something equivalent to: =HYPERLINK({"http://google.com","http://yahoo.com","http:// microsoft.com"}, {"google","yahoo","microsoft"}) ....but I just end up with an array filled with google links... Anyone have any ideas? Thanks, James hi, James ! > I've spent a good part of the day working on a few pretty complex array formulas. > I'd now l...

Using CHtmlView in my ActiveX control
I have a class CHtmlViewEx inherited from CHtmlView, the document of this class can be edited. I create a activex using MFC in vc.net 2003, in this activex control I create a CHtmlViewEx object and show it. The problem is: When I press "Enter", CHtmlViewEx will insert a <P> at the end of the "body" tag. I press "Backspace" to clear it, when there is no text in the control, CHtmlViewEx will insert <P></P>. I hope that CHtmlViewEx will insert a <BR> when I press "Enter" and won't insert "<P></P> when I press &...

Re: Using one of the LOOKUP functions
Hi everyone. I have done a search but not been able to find what I'm looking for so perhaps some kind person here may be able to give me some pointers. My dilemma is thus; I have a sheet with 11 columns of data in around 45 rows (the number of rows grows as more data get put in during the month) The first column contains people's names. At the end of the month I will sort all the data on the Name column. I then subtotal on these names and this data is contained within the 11th column. The data I want to find at the end of each month will be contained within the row that starts wit...

Use LeBans ReportToPDF in custom toolbar
I use LeBans ReportToPDF in command button to generate PDF and it works great. I have so many reports and they are all in preview when a command is clicked. I want one button on "custom toolbar" to 1. close currently previewed report 2. generate PDF from that report and ask user if you want send as email attachment. If yes: 3. attach PDF to email Can anyone help? Thanks. On Jul 5, 7:32 am, "Song Su" <csit...@hotmail.com> wrote: > I use LeBans ReportToPDF in command button to generate PDF and it works > great. > > I have so many reports and they ar...

I wish to use Visio to landscape my house. Has anyone tried this?
I am pretty comfortable with Visio and I certainly like the improvements in 2003. The subject pretty much says it. -- Ready to Retire...Tired of the drive Haven't tried yet (on my list when I am ready to retire!) Would start with Building Plan/Site Plan. You can even have a kidney shaped pool! "Bob Hatcher" <confusedagain@anywhere.com> wrote in message news:CF662BE7-2D7F-44B2-972B-F90293EB3842@microsoft.com... >I am pretty comfortable with Visio and I certainly like the improvements in > 2003. The subject pretty much says it. > -- > Ready to Retire...Tire...

Can i use Windows Search to find a number within Excel?
If i use Widnows search of the CONTENTS of files (not file names), i find in Excel, that for cells that contain text, they can be found. But, it does not appear to me that numbers can be found. Of course the number as Excel stores it may differ from how it is displayed. But, does anybody know if this is possible? For instance, i have a cell with the number 3,709,227 in it, as it appears in Excel (as formatted). I tried typing the number both with and without the commas, into WIndows search, but Windows search still does not find the Excel file that contains that number. So, any kn...

Why can't I select/use items from master page in publication pages
I created text boxes in a master page and when I go to the publication pages, I can't select any of the objects I created in the master page. It's as if they are locked. What's up with that? It's driving me bananas!!!! They are two seperate pages. You have to have the master page selected to make any alterations to it. "joyojoy" <joyojoy@discussions.microsoft.com> wrote in message news:F8A3F7D5-CEA1-483B-A782-B7707CDD74BF@microsoft.com... >I created text boxes in a master page and when I go to the publication >pages, > I can't select any of ...

Excel 2007 using combo Boxes
please can someone help me, In Excel 2003 i used Combo boxes which were in the forms tool bar and in format control had a cell link used for counting. I cannot find in Excel 2007 the forms tool bar or Combo boxes with the cell link, Can any one point me in the right direction of how to use combo boxes in Excel 2007 thanks > please can someone help me, In Excel 2003 i used Combo boxes which were in > the forms tool bar and in format control had a cell link used for > counting. I > cannot find in Excel 2007 the forms tool bar or Combo boxes with the cell > link, Can any one...

best deal with value pairs that contain duplicates
Hi, I'm sorry if I'm asking for the obvious - my head is spinning a bit trying to learn this c# stuff. I have a list of paired values in the form of: stringA, string1 stringB, string2 stringC, string1 stringC, string3 stringD, string2 etc.. I need to store these value pairs into some kind of collection. Since I do not have unique 'keys', I cannot use a Dictionary or SortedList. The combination of -say- stringA+string1 *will* be unique. (if case-sensitive). That could serve as a key, but then I need to store 2 values. My goal is to query the collection f...

What xml data type would I use for tinyint?
I'm bringing data from sql server into xml and one column is a tinyint data type in sql server. what's the equivalent of tinyint in xml? Thanks. -- moondaddy@nospam.com unsignedByte. See http://www.w3.org/TR/xmlschema-2/#unsignedByte tch�s, Wole "moondaddy" <moondaddy@nospam.com> wrote in message news:%23DyTCva2EHA.2608@TK2MSFTNGP10.phx.gbl... > I'm bringing data from sql server into xml and one column is a tinyint > data type in sql server. what's the equivalent of tinyint in xml? > > Thanks. > > -- > moondaddy@nospam.com >...

use excel to create PP slides?
I'm not sure if this is possible but I have a list of information in an excel table and I'd like to auto matically generate a slide for each row of data. for instance, I have a list of products and each product is on it's own row with 6 product features in the following columns. How can I take that info from excel and create a features slide for each product using the information from the following columns. I don't mind cutting and pasting the list - it doesn't have to be fully automatic but as I have over 1000 products I desperately don't want to reype ...

use isc calender file on local filesystem
Hi, I want to use ICS calenderfiles in outlook 2010. Let's say one file is at c:\calender.ics. What URL do I use in Outlook? There is only one example "webcal://www.xyz.com/calender.ics". But I want to use the local filesystem. I have tried several possibilities but nothing worked. TIA Martin ...

Copy and paste not working
A user in our department regularly copies data from a non-Microsoft program (Business Objects) to Excel 2003. By selecting "Copy All" in Business Objects, she usually has no difficulty in copying and pasting the data to Excel. However, at least once or twice a week the copy and paste function stops working (the "Paste" is grayed out when she right clicks in Excel,and CTRL V doesn't work either) and she has to reboot her computer, which is obviously a frustration and waste of time. I looked at her computer today and went to Edit > Office Clipboard, but the erro...