• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

parsing XML file in c#

I know this is going to be easy but I am stumped

I have an xml file that I am parsing.  I have it all set up great and it works all the way until there is a record that is missing data

let me give an example

I am only concerned about the AMOUNT field

normally the XML file would look like this

- <zestimate>
  <amount currency="USD">151515</amount>
  <last-updated>01/11/2010</last-updated>
  <oneWeekChange deprecated="true" />
  <valueChange />
- <valuationRange>
  <low currency="USD" />
  <high currency="USD" />
  </valuationRange>
  <percentile>0</percentile>
  </zestimate>


the snag is when there is no value in amount, it looks like this

- <zestimate>
  <amount currency="USD" />
  <last-updated>01/11/2010</last-updated>
  <oneWeekChange deprecated="true" />
  <valueChange />
- <valuationRange>
  <low currency="USD" />
  <high currency="USD" />
  </valuationRange>
  <percentile>0</percentile>
  </zestimate>

and that causes an error in my file



here is my code
zestval = root.SelectSingleNode("//response/results/result/zestimate/amount").ChildNodes[0].Value;

I have tried

if (root.SelectSingleNode("//response/results/result/zestimate/amount").ChildNodes[0].Value != null)
      zestval = root.SelectSingleNode("//response/results/result/zestimate/amount").ChildNodes[0].Value;
else
      zestval = "0";

and when I do a Response.Write(zestval);
nothing comes up



who would I parse it so if there is NO value in amount it just puts a zero?  


0
bob1barker
Asked:
bob1barker
1 Solution
 
bob1barkerAuthor Commented:
I solved it with a

if (root.SelectSingleNode("//response/results/result/zestimate/amount").InnerXml == "")
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now