EDN Admin
Well-known member
If am receiving an XML string from a web call and would like to convert it to a Value String. I am thinking LINQ to XML might be perfect for this, but dont know how to do it.
Here is a sample of what I am trying to accomplish:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ2XML
{
class Program
{
static void Main(string[] args)
{
//List<Offer> Offers = LINQ to XML statement
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ2XML
{
public class Offer
{
public string Id { get; set; }
public string Name { get; set; }
public string Link { get; set; }
public string ScoreDisplay { get; set; }
public List<string> Bullets { get; set; }
public List<string> CreditScores { get; set; }
public List<string> Brands { get; set; }
public List<string> Rewards { get; set; }
public List<string> Features { get; set; }
public List<string> Countries { get; set; }
public decimal Apr { get; set; }
public string AprDisplay { get; set; }
public decimal? IntroApr { get; set; }
public string IntroAprDisplay { get; set; }
public string IntroDisplayPeriod { get; set; }
public string IntroAprPeriodDisplay { get; set; }
public int AnnualFee { get; set; }
public string AnnualFeeDisplay { get; set; }
public decimal? BalanceTransfer { get; set; }
public string BalanceTransferDisplay { get; set; }
}
}
<offers>
<offer>
<id>iberiabank_visa_select-creditcardoffers</id>
<name><![CDATA[IBERIABANK Visa® Select]]></name>
<link><![CDATA[http://www.credit.com/r/iberia-visa-select/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[Introductory Rate of 0.00% or 7.50% based on creditworthiness for 12 months from date opened on Purchases. This rate will not change during the introductory period.]]></bullet>
<bullet><![CDATA[Online access to credit card account information]]></bullet>
<bullet><![CDATA[Product Enhancements include: Auto Rental Collision Damage Waiver, Roadside Dispatch and Travel Emergency Services.]]></bullet>
<bullet><![CDATA[Low Annual Fee of $35.00.]]></bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_iberia-visa-select.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_iberia-visa-select.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_iberia-visa-select.png</image-lg>
<credit-scores>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>IBERIABANK</brand>
<brand>Visa</brand>
</brands>
<rewards>
</rewards>
<features>
<feature>Balance Transfers</feature>
<feature>Low APR</feature>
</features>
<countries>
<country>USA</country>
</countries>
<apr>7.50</apr>
<apr-display><![CDATA[7.50%-11.50% variable]]></apr-display>
<intro-apr/>
<intro-apr-display><![CDATA[N/A]]></intro-apr-display>
<intro-apr-period> for 12 months</intro-apr-period>
<intro-apr-period-display><![CDATA[0.00% or 7.50% based on creditworthiness for 12 months]]></intro-apr-period-display>
<annual-fee>35</annual-fee>
<annual-fee-display><![CDATA[$35]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display>
<![CDATA[
Intro:
1.99% or 7.50% based on creditworthiness 12 months]]>
</balance-transfer-display>
</offer>
<offer>
<id>amex_gold_delta_skymiles-americanexpresscreditcardoffers</id>
<name><![CDATA[Gold Delta SkyMiles® Business Credit Card from American Express]]></name>
<link><![CDATA[http://www.credit.com/r/American-Express-Gold-Delta-SkyMiles-Business-Credit-Card/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[Get 30,000 bonus miles after you spend $500 in purchases on the Card within your first 3 months of Cardmembership]]></bullet>
<bullet><![CDATA[You can check your first bag for free and save up to $50 on a round-trip Delta flight]]></bullet>
<bullet><![CDATA[2x miles for each dollar spent on qualifying Delta purchases and 1x mile for each dollar spent on other eligible purchases]]></bullet>
<bullet><![CDATA[Terms and Restrictions Apply]]></bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_AmEx-Gold-Delta-SkyMiles-Business-Credit-Card.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_AmEx-Gold-Delta-SkyMiles-Business-Credit-Card.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_AmEx-Gold-Delta-SkyMiles-Business-Credit-Card.png</image-lg>
<credit-scores>
<credit-score>Very Good</credit-score>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>American Express</brand>
</brands>
<rewards>
</rewards>
<features>
<feature>Business</feature>
</features>
<countries>
<country>USA</country>
</countries>
<apr>15.24</apr>
<apr-display><![CDATA[15.24%-19.24% Variable]]></apr-display>
<intro-apr>None</intro-apr>
<intro-apr-display><![CDATA[None]]></intro-apr-display>
<intro-apr-period/>
<intro-apr-period-display><![CDATA[N/A]]></intro-apr-period-display>
<annual-fee/>
<annual-fee-display><![CDATA[$0 introductory annual fee for the first year, then $95]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display><![CDATA[N/A]]></balance-transfer-display>
</offer>
<offer>
<id>american-express-starwood-preferred-guest-credit-card-canada-americanexpresscreditcardoffers</id>
<name><![CDATA[Starwood Preferred Guest®* Credit Card from American Express®]]></name>
<link><![CDATA[http://www.credit.com/r/starwood-preferred-guest-american-express-canada/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[Earn 10,000 Welcome Bonus Starpoints®* after you charge $1,000 in purchases to your Card in your first three months of Cardmembership.]]></bullet>
<bullet><![CDATA[Earn 1 Starpoint®* for every $1 in purchases charged to the Card.]]></bullet>
<bullet><![CDATA[* Terms and conditions apply]]></bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_america-express-canada-starwood-preferred-guest.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_america-express-canada-starwood-preferred-guest.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_america-express-canada-starwood-preferred-guest.png</image-lg>
<credit-scores>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>American Express</brand>
</brands>
<rewards>
<reward>Airline Miles</reward>
</rewards>
<features>
</features>
<countries>
<country>CA</country>
</countries>
<apr>19.99</apr>
<apr-display><![CDATA[19.99%]]></apr-display>
<intro-apr/>
<intro-apr-display><![CDATA[N/A]]></intro-apr-display>
<intro-apr-period/>
<intro-apr-period-display><![CDATA[N/A]]></intro-apr-period-display>
<annual-fee>120</annual-fee>
<annual-fee-display><![CDATA[$120 Annual Fee]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display><![CDATA[N/A]]></balance-transfer-display>
</offer>
<offer>
<id>disccover-it-version-two-creditcardoffers</id>
<name><![CDATA[Discover it®]]></name>
<link><![CDATA[http://www.credit.com/r/discover-it-eighteen-month-bt/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[The new Discover it card is out to change the way people think about credit cards.]]></bullet>
<bullet><![CDATA[Fair...No annual fee. No overlimit fee. No foreign transaction fee and no pay-by-phone fee. No late fee on your first late payment. And we wont increase your APR for paying late.*]]></bullet>
<bullet>
<![CDATA[Generous...5% Cashback Bonus on up to $1,500 in purchases at Home Improvement Stores
now through June with free and easy sign-up. And 1% cash back on all other purchases.*]]>
</bullet>
<bullet>
<![CDATA[0% Intro APR* on balance transfers for 18 months. Then the variable purchase APR applies, currently 10.99% - 22.99%.
0% Intro APR* on purchases for 6 months. Then the variable purchase APR applies, currently 10.99% - 22.99% *Click apply for Terms and Conditions.]]>
</bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_discover-it-card.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_discover-it-card.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_discover-it-card.png</image-lg>
<credit-scores>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>Discover</brand>
</brands>
<rewards>
</rewards>
<features>
</features>
<countries>
<country>USA</country>
</countries>
<apr>10.99</apr>
<apr-display><![CDATA[10.99-22.99% (V)*]]></apr-display>
<intro-apr>0</intro-apr>
<intro-apr-display><![CDATA[0%]]></intro-apr-display>
<intro-apr-period>6 months</intro-apr-period>
<intro-apr-period-display><![CDATA[6 months]]></intro-apr-period-display>
<annual-fee>0</annual-fee>
<annual-fee-display><![CDATA[$0]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display>
<![CDATA[
Intro:
0% 18 months]]>
</balance-transfer-display>
</offer>
</offers>I dont need some elements, such as <image-sm/>
View the full article
Here is a sample of what I am trying to accomplish:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ2XML
{
class Program
{
static void Main(string[] args)
{
//List<Offer> Offers = LINQ to XML statement
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINQ2XML
{
public class Offer
{
public string Id { get; set; }
public string Name { get; set; }
public string Link { get; set; }
public string ScoreDisplay { get; set; }
public List<string> Bullets { get; set; }
public List<string> CreditScores { get; set; }
public List<string> Brands { get; set; }
public List<string> Rewards { get; set; }
public List<string> Features { get; set; }
public List<string> Countries { get; set; }
public decimal Apr { get; set; }
public string AprDisplay { get; set; }
public decimal? IntroApr { get; set; }
public string IntroAprDisplay { get; set; }
public string IntroDisplayPeriod { get; set; }
public string IntroAprPeriodDisplay { get; set; }
public int AnnualFee { get; set; }
public string AnnualFeeDisplay { get; set; }
public decimal? BalanceTransfer { get; set; }
public string BalanceTransferDisplay { get; set; }
}
}
<offers>
<offer>
<id>iberiabank_visa_select-creditcardoffers</id>
<name><![CDATA[IBERIABANK Visa® Select]]></name>
<link><![CDATA[http://www.credit.com/r/iberia-visa-select/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[Introductory Rate of 0.00% or 7.50% based on creditworthiness for 12 months from date opened on Purchases. This rate will not change during the introductory period.]]></bullet>
<bullet><![CDATA[Online access to credit card account information]]></bullet>
<bullet><![CDATA[Product Enhancements include: Auto Rental Collision Damage Waiver, Roadside Dispatch and Travel Emergency Services.]]></bullet>
<bullet><![CDATA[Low Annual Fee of $35.00.]]></bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_iberia-visa-select.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_iberia-visa-select.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_iberia-visa-select.png</image-lg>
<credit-scores>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>IBERIABANK</brand>
<brand>Visa</brand>
</brands>
<rewards>
</rewards>
<features>
<feature>Balance Transfers</feature>
<feature>Low APR</feature>
</features>
<countries>
<country>USA</country>
</countries>
<apr>7.50</apr>
<apr-display><![CDATA[7.50%-11.50% variable]]></apr-display>
<intro-apr/>
<intro-apr-display><![CDATA[N/A]]></intro-apr-display>
<intro-apr-period> for 12 months</intro-apr-period>
<intro-apr-period-display><![CDATA[0.00% or 7.50% based on creditworthiness for 12 months]]></intro-apr-period-display>
<annual-fee>35</annual-fee>
<annual-fee-display><![CDATA[$35]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display>
<![CDATA[
Intro:
1.99% or 7.50% based on creditworthiness 12 months]]>
</balance-transfer-display>
</offer>
<offer>
<id>amex_gold_delta_skymiles-americanexpresscreditcardoffers</id>
<name><![CDATA[Gold Delta SkyMiles® Business Credit Card from American Express]]></name>
<link><![CDATA[http://www.credit.com/r/American-Express-Gold-Delta-SkyMiles-Business-Credit-Card/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[Get 30,000 bonus miles after you spend $500 in purchases on the Card within your first 3 months of Cardmembership]]></bullet>
<bullet><![CDATA[You can check your first bag for free and save up to $50 on a round-trip Delta flight]]></bullet>
<bullet><![CDATA[2x miles for each dollar spent on qualifying Delta purchases and 1x mile for each dollar spent on other eligible purchases]]></bullet>
<bullet><![CDATA[Terms and Restrictions Apply]]></bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_AmEx-Gold-Delta-SkyMiles-Business-Credit-Card.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_AmEx-Gold-Delta-SkyMiles-Business-Credit-Card.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_AmEx-Gold-Delta-SkyMiles-Business-Credit-Card.png</image-lg>
<credit-scores>
<credit-score>Very Good</credit-score>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>American Express</brand>
</brands>
<rewards>
</rewards>
<features>
<feature>Business</feature>
</features>
<countries>
<country>USA</country>
</countries>
<apr>15.24</apr>
<apr-display><![CDATA[15.24%-19.24% Variable]]></apr-display>
<intro-apr>None</intro-apr>
<intro-apr-display><![CDATA[None]]></intro-apr-display>
<intro-apr-period/>
<intro-apr-period-display><![CDATA[N/A]]></intro-apr-period-display>
<annual-fee/>
<annual-fee-display><![CDATA[$0 introductory annual fee for the first year, then $95]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display><![CDATA[N/A]]></balance-transfer-display>
</offer>
<offer>
<id>american-express-starwood-preferred-guest-credit-card-canada-americanexpresscreditcardoffers</id>
<name><![CDATA[Starwood Preferred Guest®* Credit Card from American Express®]]></name>
<link><![CDATA[http://www.credit.com/r/starwood-preferred-guest-american-express-canada/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[Earn 10,000 Welcome Bonus Starpoints®* after you charge $1,000 in purchases to your Card in your first three months of Cardmembership.]]></bullet>
<bullet><![CDATA[Earn 1 Starpoint®* for every $1 in purchases charged to the Card.]]></bullet>
<bullet><![CDATA[* Terms and conditions apply]]></bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_america-express-canada-starwood-preferred-guest.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_america-express-canada-starwood-preferred-guest.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_america-express-canada-starwood-preferred-guest.png</image-lg>
<credit-scores>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>American Express</brand>
</brands>
<rewards>
<reward>Airline Miles</reward>
</rewards>
<features>
</features>
<countries>
<country>CA</country>
</countries>
<apr>19.99</apr>
<apr-display><![CDATA[19.99%]]></apr-display>
<intro-apr/>
<intro-apr-display><![CDATA[N/A]]></intro-apr-display>
<intro-apr-period/>
<intro-apr-period-display><![CDATA[N/A]]></intro-apr-period-display>
<annual-fee>120</annual-fee>
<annual-fee-display><![CDATA[$120 Annual Fee]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display><![CDATA[N/A]]></balance-transfer-display>
</offer>
<offer>
<id>disccover-it-version-two-creditcardoffers</id>
<name><![CDATA[Discover it®]]></name>
<link><![CDATA[http://www.credit.com/r/discover-it-eighteen-month-bt/af=p97906&ag=none]]></link>
<score-display><![CDATA[Excellent]]></score-display>
<bullets>
<bullet><![CDATA[The new Discover it card is out to change the way people think about credit cards.]]></bullet>
<bullet><![CDATA[Fair...No annual fee. No overlimit fee. No foreign transaction fee and no pay-by-phone fee. No late fee on your first late payment. And we wont increase your APR for paying late.*]]></bullet>
<bullet>
<![CDATA[Generous...5% Cashback Bonus on up to $1,500 in purchases at Home Improvement Stores
now through June with free and easy sign-up. And 1% cash back on all other purchases.*]]>
</bullet>
<bullet>
<![CDATA[0% Intro APR* on balance transfers for 18 months. Then the variable purchase APR applies, currently 10.99% - 22.99%.
0% Intro APR* on purchases for 6 months. Then the variable purchase APR applies, currently 10.99% - 22.99% *Click apply for Terms and Conditions.]]>
</bullet>
</bullets>
<image-sm>https://static.ccom-cdn.com/assets/img/creditCards/xs/xs_discover-it-card.png</image-sm>
<image-rg>https://static.ccom-cdn.com/assets/img/creditCards/rg/rg_discover-it-card.png</image-rg>
<image-lg>https://static.ccom-cdn.com/assets/img/creditCards/lg/lg_discover-it-card.png</image-lg>
<credit-scores>
<credit-score>Excellent</credit-score>
</credit-scores>
<brands>
<brand>Discover</brand>
</brands>
<rewards>
</rewards>
<features>
</features>
<countries>
<country>USA</country>
</countries>
<apr>10.99</apr>
<apr-display><![CDATA[10.99-22.99% (V)*]]></apr-display>
<intro-apr>0</intro-apr>
<intro-apr-display><![CDATA[0%]]></intro-apr-display>
<intro-apr-period>6 months</intro-apr-period>
<intro-apr-period-display><![CDATA[6 months]]></intro-apr-period-display>
<annual-fee>0</annual-fee>
<annual-fee-display><![CDATA[$0]]></annual-fee-display>
<balance-transfer/>
<balance-transfer-display>
<![CDATA[
Intro:
0% 18 months]]>
</balance-transfer-display>
</offer>
</offers>I dont need some elements, such as <image-sm/>
View the full article