J
Jon
Hi All,
I'm trying to parse an XML document that has optional fields.
Eg.
<parts>
<part>
<id>1</id>
<description>Item 1</description>
<length>34.5</length>
<qty>3</qty>
</part>
<part>
<id>2</id>
<description>Item 2</description>
<qty>4</qty>
</part>
</parts>
A part can sometimes have a length field.
I am parsing this with ..
var parts = from p in xmlFile.Elements("parts").Elements("part")
select new
{
Id = (int)p.Element("id"),
Description =
(string)p.Element("description"),
Qty = (float)p.Element("qty"),
Length =
(float)p.Element("length")
};
I would like the Length set to 0 if it does not exist in the XML - How can I
acheive this?
I'm trying to parse an XML document that has optional fields.
Eg.
<parts>
<part>
<id>1</id>
<description>Item 1</description>
<length>34.5</length>
<qty>3</qty>
</part>
<part>
<id>2</id>
<description>Item 2</description>
<qty>4</qty>
</part>
</parts>
A part can sometimes have a length field.
I am parsing this with ..
var parts = from p in xmlFile.Elements("parts").Elements("part")
select new
{
Id = (int)p.Element("id"),
Description =
(string)p.Element("description"),
Qty = (float)p.Element("qty"),
Length =
(float)p.Element("length")
};
I would like the Length set to 0 if it does not exist in the XML - How can I
acheive this?