XMLElement with childnodes as a parameter to ReadOnlyBase?

XMLElement with childnodes as a parameter to ReadOnlyBase?

Old forum URL: forums.lhotka.net/forums/t/2780.aspx


colema18 posted on Wednesday, April 25, 2007

This is blowing up.  It appears to only blow up if the Node has child nodes.  Can someone tell me what I am doing wrong? (It blows up on the "Taxes" node).

PayoffQuote.cs
private
void Fetch(Criteria crit)
{
  int i = 0;
  XmlDocument doc = new XmlDocument();
  doc.Load(
"C:\\Clients\\FinanceSource\\FinanceSource.Library\\xml\\MockLease.xml");
  XmlElement root = doc.DocumentElement;
  XmlNode quoteInfo = root.ChildNodes[0];
  foreach (XmlElement detail in quoteInfo.ChildNodes)
  {
     if(detail.Name == "QuoteDetail")
    {
         QuoteDetails.Add(i,
new QuoteDetail(detail));
         i += 1;
     }
  }
}

QuoteDetail.cs
public QuoteDetail(XmlElement detailNode)
{
  int i = 0;
  _title = detailNode.Attributes[
"Text"].Value;
  if(detailNode.HasAttribute("Amount"))
  {
     _amount =
double.Parse(detailNode.Attributes["Amount"].Value);
  }
  if(detailNode.HasChildNodes)
  {
     foreach (XmlElement detail in detailNode.ChildNodes)
  {
  QuoteDetails.Add(i,
new QuoteDetail(detail));
  i += 1;
}

MockLease.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<
PayoffQuote>
<
QuoteInformation>
<
QuoteDetail Text="Residual Value (Purchase Option Amount)" Amount="10585.00"/>
<
QuoteDetail Text="Taxes">
<
QuoteDetail Text="Sales Tax" Amount="10"/>
<
QuoteDetail Text="Transport Tax" Amount="20"/>
<
QuoteDetail Text="RipOff Tax" Amount="30.50"/>
</
QuoteDetail>
</QuoteInformation>
</
PayoffQuote>

Thanks

~james

colema18@gmail.com

skagen00 replied on Thursday, April 26, 2007

I'm afraid I don't work with XML too often, but I will tell you there was a strange </font> tag in the email I received from your post. (I'm going say closing "font" element in case my text gets rendered as HTML) This font tag appears between the last quotedetail closing node and the quoteinformation closing node.

You also appear to have an extra closing node of QuoteDetail.

Perhaps your file isn't formed well.

Here's a cut and paste of the MockLease file as I saw it in my e-mail (assuming it shows properly)

<?xml version="1.0" encoding="utf-8" ?>
<
PayoffQuote>
<
QuoteInformation>
<
QuoteDetail Text="Residual Value (Purchase Option Amount)" Amount="10585.00"/>
<
QuoteDetail Text="Taxes">
<
QuoteDetail Text="Sales Tax" Amount="10"/>
<
QuoteDetail Text="Transport Tax" Amount="20"/>
<
QuoteDetail Text="RipOff Tax" Amount="30.50"/>
</
QuoteDetail>
< /FONT></QuoteInformation>
</
PayoffQuote>

 

 

colema18 replied on Thursday, April 26, 2007

I think the post just didn't come through in email.  There is no font tag, and the nodes might have gotten messed up in the email.  The code looks right via the web site post.  I still have the problem if anyone else can try it out.  It blows up when it recursively calls itself.  I am sure it is something silly that I am missing.  It is rather frustrating because the only reason I am doing this is because I am mocking out the data until the backend is available - so this quick mock approach is actually taking a lot more effort than I anticipated.

colema18 replied on Friday, April 27, 2007

Well it was a silly mistake and not even CSLA related, so sorry for the post.  It turned out I neglected to actually instantiated my sortedlist before I added something to it.

Copyright (c) Marimer LLC