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
615 Views

Similar Articles

[PageSpeed] 34

* 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:

Change Exchange to use ISP mail server
We are currently listed on the SORBS site and as a result we are unable to send mail to a certain domain. We ARE NOT an open realy and the resulting listing is simply because we are using our Exchange server to send mail and not sending it through our ISP mail server. While I think this is a rather harsh rule it means I have to reconfigure our server to send through our ISP mail server. Is this a simple as doing the following: Exchange Console Connection IMS Connections and then FORWARD ALL MESAGES TO HOST radio button? Once there simply giving it our ISP mail server name or IP? TIA Bryan ...

Imported 'Sent Items' from Outlook Express appears to be empty
I just migrated from OE6 to Windows Live Mail. I have always stored a LOT of messages in my inbox and sent items folders. Don't know if this is causing a problem. Everything seems to have gone well with my installation and imports from OE6, except that my 'Sent Items' are not showing up. If I try to re-do the import, it says that it has been done. The inbox items were successfully imported from the .dbx file; the problem seems to be primarily with the 'sent items'. (The .dbx file in my OE folder is just over 2GB.) I don't want to start using Windows Live M...

How to add xsi:schemaLocation attribute to XML element
Hi all, I am trying to serialize a C# object into a XML document using "XmlSerializer" class. One of the elements of the XML document needs a "xsi:schemaLocation" attribute. I am not sure how to add this to the XML element Please help me with if you can. Thanks, kaush The root element of the document can contain, along with all the xmlns stuff, an attribute called xsi:schemaLocation="namespaceURI filename.xsd" There are two tokens inside the single string. This is a hint for the validator to know where to find a physical xsd file to...

how to retrieve current values assigned for names used in EXCEL?
I got a spread sheet from some one else. There were formulas used using names. I like to retrieve the values used for different names used in the formulas. Please let me know for any questions. Rao goto <insert><names><define> and you will be able to find the names and either cells, values or formulas assigned to the names. "yrk" wrote: > I got a spread sheet from some one else. There were formulas used using names. > I like to retrieve the values used for different names used in the formulas. > > Please let me know for any questions. > > R...

how to deal with reimbursement?
Hi, I created a sub category "reimbursement" in the "health" category. My goal is that the health expenses represent really what it costed me. The problem is that the "health" category display only shows debits. It doesn't take into account the reimbursements. In the same manner, for the budget, health reimbursements only appear as revenues. I didn't find any way to deduct them from the health expenses. I encounter the same problem with business expenses: I have to do myself the difference between expenses and reimbursement. Have somebody find any...

How to deal with task bar
I am using XP SP3, I am trying to look at a series of .mov files in a folder, one file at a time. When I double click on one of the .mov files, it quite naturally executes Quicktime V7.0 to 'play' the .mov, since that is the default for .mov files. What I don't like is that Quicktime always opens to play the .mov with its 'play' button (and its other controls too) hidden behind the task bar at the bottom of the screen. I can manually shrink Quicktime's window so as to expose the play button, but how can I make Quicktime come up automatically on top of the ta...

Error using offset
compile error: invalid or unqualified reference Sub APPLES() 'COPY OP FNAME & PASTE Sheets("Correct").Select Range("g2").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("Errors").Select Range("AA6500").Select Selection.End(xlUp).Select .Offset(1, 0).Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False End Sub The line > .Offset(1, 0).Select needs to q...

Failed to return new Code Element. Possibly syntax error
Using VC++.Net 2003, I get this message when I right click on a class in Class View then click "Add" then "Add Function" choose return type "void", Function Name "SetValue" and no args. click "Finish" Then I get the message. Failed to return new Code Element. Possibly syntax error: New Element Name: .\filename.h It is the only class (of almost 100) in the project that has this problem. (Similar problem when trying to add a member variable.) What could cause this? Thanks- Steve As far as I can tell, this is an example of the egregiou...

Using autofilter in VBA
Hello, I would like to know if it is possible copy the data in excel column to a variable using the autofilter. I have a huge amount of data repeated in a column, like: 18189 18189 18189 18189 18189 ... 18190 18190 18190 18190 18190 ... 18191 18191 ... And I just want the single data, without repetition, like: 18189 18190 18191 ... I know that it could be done with a "for" cicle, but it takes a lot of time running, because the excel sheet have around of 60 000 lines of data. So, the autofilter gives me the data without repetition right? can I get...

Outlook Public Folder View
I'm trying to edit a filtered view in Outlook. I'm fairly sure my SQL is correct, but the nesting order is not. I'm trying to not display subjects with Advanced Search Tool or Recall: ("urn:schemas:httpmail:subject" <> 'Advanced Search Tool' AND "urn:schemas:httpmail:subject" <> 'Recall:' AND (("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000- C000-000000000046}/Assigned%20To" IS NULL OR "http:// schemas.microsoft.com/mapi/proptag/0x10900003" IS NULL OR "http:// schemas.microsoft.com/mapi/propt...

60 GB IPOD deal found #2
I just completed this offer for a 60 gb photo ipod and it is awesome! My friend got one from it and he is waving it in my face and taunting me! Anyways, all you have to do is complete a promotion offer and cancel it before the 30 days trial is up and then get 8 referrals. I recommend doing the rhapsody promotion because it is only $0.99 and you get instant credit towards your ipod. It is so cool. Check it out. http://www.freephotoiPods.com/?r=21360900 I'm goner have your gmail account closed as well. ...

Create Login in asp.net using XML
Hi. I'm trying to create a login page in asp.net using information from an XML document. (visual basic) I've tried Rowfilter to find a cell with the 'username' and then match this with the 'Password' cell on the same row.... -> allow page to redirect if these match: If 'username' match 'password' then "redirect to next page" else "Error message" Does anyone know how to create this login function? Thank you for all help. M This could look something like this: 1) Create two text fields in a form. 1.1) Textfield Username 1...

Spaces Are Displayed Incorrectly When Using MS Word as Editor
Windows 2K Pro. Office XP Pro. Outlook 2002. Using MS Word as message editor for Outlook. Outlook uses OST. Spaces are displayed wrong - as dots at half the height of a lower-space letter (in English) or as empty squares (in Japanese). Anybody experienced this problem before? Seems like re- createing the profile does not solve the problem. Re- installing MS Office also did not help. ...

Dealing with dxf
Does Visio import/export the vector filetype .dxf? I need this format for use with a cnc machine. I see from some earlier comments (via google group search) that exporting dxf files produces some unwanted characteristics, like other vector apps such as AutoCAD can view but cannot edit them. Has this been improved recently? Thanks -- Auckland NEW ZEALAND DXF is essentially the publicly documented transfer format for AutoCAD. While it is not quite a robust as the DWG format, it is quite suitable for many applications including process control. DXF can be read and modified by AutoCAD....

coping with empty excel cells in the xml document
Hi I have an xml document that has been created from an excel spreadsheet. In the s/s there are some empty cells however these are not captured in the xml file. All that is added is for the cell after where the empty cell should be, it has an extra attribute: "ss:Index="6", where it is the 6th cell in the row, and cell 5 had no entry. I'm wanting to pick out a particular cell from a particular column however just iterating through the cells is going to give me invalid values where there should have been empty cells. Does anyone know how to handle this? I've tried ch...

outlook .pst files appear empty
I have been trying to open, import, and even restore backup for a .pst file I made before reinstalling Windows on my computer. The import seems to work correctly but nothing changes. What is happening. I tried to install them on another computer running the same version of Outlook and the same thing. The file size is large enought to tell me something is there but........I don't know what to do. So if you open the files in Outlook using File | Open | Outlook Data File (command may vary if you're using an older version), you still get empty files in your Folder List? -- Jo...

Find Empty Distribution Lists
Hi, How can export to a file a list of all Distribution Lists that have no members? Thanks. You can use CSVDE to dump these to a CSV file. csvde -f emptyDistributionLists.csv -d "dc=my-domain-name,dc=com" -r "(&(objectClass=group)(|(groupType=2)(groupType=4)(groupType=8))(!member=*))" -l name *replace dc=my-domain-name,dc=com with your domain name and extension. -- Bharat Suneja MVP - Exchange www.zenprise.com NEW blog location: www.exchangepedia.com/blog ---------------------------------------------- "markj" <markj@discussions.microsoft.com> ...

Using Document Hyperlinks in Email Publications
I thought I had read somewhere that you could use hyperlinks to documents in your email publications (where the documents are not saved on a web server). I was under the impression that the documents sort of "upload" and give the reader the option to "open" or "save" them. Is there a trick to doing this, if it is possible at all? Thanks You could "attach" the document to your email. In the body of the email give a statement, i.e., See attached file. Before sending the email, click on the Attach icon on the tool bar at the top which will give y...

Dealing with being broke!
Dealing with being broke! http://www.helium.com/tm/163934/being-broke-state-those ...

Why do I get letters inserted when I use up arrow
When I arrow thru a document - a "c" or a "d" is inserted in my text creating a spelling error. I don't know why this happens..I am not touching those keys..just the arrows ...

Contact Set Up for Personal Use
I use Outlook 2003 and was wondering if there is a better way to set up my contacts for personal use. For example, our family has another family in our address book. There are multiple contacts with multiple email addresses and phone numbers for the other family, although they are all at the same mailing address which I use when I send a Christmas card or something. Rather than having four separate contacts, is there a way to combine it into one and still be able to find the members' information that are the primary contact? I guess this would be like finding staff members within a com...

Using a Symbol in a formula.
I want to display a symbol in a cell, the symbol displayed depends on the cell next to it being a positive number or negative number. I would like to have this in the form of a IF(A1>0,TRUE,FALSE) where different symbols would appear for true and false. Any one have a way to do this? First, find the ASCII character code for the symbol you wish to display. Then use a formula like =IF(A1>0,CHAR(mmm),CHAR(nnn)) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "JB in Kansas" <JBinKansas@discussions.microsoft.com>...

Help dealing with "#N/A" (in general, but specifically with VLOOKUP)
Are there some tips for handling the #n/a errors? They really screw u my spreadsheets, but sometimes the outputs are unavoidable. Wha irritates me most is that Excel doesn't seem to acknowledge them as an number, not even zero. For example, I may have a list of values that I want to add, and i there is a #n/a in the list, the summation will not work. Worse yet even a SUMIF doesn't seem to work. Are there ways to quickly remove, or have excel just put a zero in th cell instead? As for a specific problem, I am using VLOOKUP right now on an arra with 2000 items in column A. The arr...

Populate Excel form using Access
I have a form created in Excel that must be filled out with 200 different sets of information to create 200 different forms. Is it possible to do this using an access database I create? I would like it to product the 200 forms all at once so I do not have to print them individually. "BML" <BML@discussions.microsoft.com> wrote in message news:4A41E066-89D0-413E-B9C9-A4845AD80A86@microsoft.com... >I have a form created in Excel that must be filled out with 200 >different > sets of information to create 200 different forms. Is it possible to > do this ...

Using Filter
I use filters very frequently and want to know some keyboard shortcu whereby the drop down list of filtered line comes automatically instea of using the mouse -- Message posted from http://www.ExcelForum.com If you are in the filter drop down cell, use ALT+DownArrow. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "vikesh >" <<vikesh.16rdsf@excelforum-nospam.com> wrote in message news:vikesh.16rdsf@excelforum-nospam.com... > I use filters very frequently and want to know some keyboard shortcut > whereby the ...