2010-10-08 4 views
0

J'ai un peu de XML et je dois être capable de lire les données à l'intérieur.linq à xml naviguer à travers xml C#

Un échantillon du XML est

<?xml version="1.0" ?> 
<ConsumeLeadRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <LeadType>Mortgage</LeadType> 
    <LeadXml> 
    <ns1:LeadAssigned xmlns:ns1="http://YaddaYadda" xmlns:ns0="http://YaddaYadda" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <ns0:Lead> 
     <Reference>1234</Reference> 
     <Product> 
      <Mnemonic>Mortgage</Mnemonic> 
      <Description>Mortgage Leads</Description> 
      <SubType>Other</SubType> 
     </Product> 
     <ExtendedInfo> 
      <Mortgage> 
      <MortgageValue>75000</MortgageValue> 
      <MortgageValueLowerBound>1</MortgageValueLowerBound> 
      <MortgageValueUpperBound>500</MortgageValueUpperBound> 
      <PropertyValue>100000</PropertyValue> 
      <PropertyValueLowerBound>1</PropertyValueLowerBound> 
      <PropertyValueUpperBound>500</PropertyValueUpperBound> 
      <Adverse>false</Adverse> 
      <FirstTime>false</FirstTime> 
      </Mortgage> 
     </ExtendedInfo> 
     <Applicants> 
      <Applicant1> 
      <Title>Mr</Title> 
      <Forename>SampleForename</Forename> 
      <Surname>SampleSurname</Surname> 
      <DateOfBirth>1903-02-01</DateOfBirth> 
      <Smoker>false</Smoker> 
      <TelephoneNumbers> 
       <TelephoneNumber> 
       <Number>01244123456</Number> 
       <Type>Mobile</Type> 
       </TelephoneNumber> 
      </TelephoneNumbers> 
      <EmailAddresses> 
       <EmailAddress> 
       <Email>[email protected]</Email> 
       <Type>Business</Type> 
       </EmailAddress> 
      </EmailAddresses> 
      <Addresses> 
       <Address> 
       <Street>Sample Street</Street> 
       <District>Sample District</District> 
       <Town>Sample Town</Town> 
       <County>Sample County</County> 
       <Postcode>CH53UZ</Postcode> 
       <Type>Home</Type> 
       </Address> 
      </Addresses> 
      </Applicant1> 
     </Applicants> 
     </ns0:Lead> 
     <Assignment> 
     <Price>20</Price> 
     <AssignmentDateTime>2010-02-01T00:00:00</AssignmentDateTime> 
     <Subscription> 
      <Reference>1234</Reference> 
      <Subscriber> 
      <Title>Mr</Title> 
      <Forename>SampleForename</Forename> 
      <Surname>SampleSurname</Surname> 
      </Subscriber> 
     </Subscription> 
     <Account> 
      <Reference>1234</Reference> 
      <CompanyName>Sample Company</CompanyName> 
     </Account> 
     <LeadType>SampleLeadType</LeadType> 
     <TerritoryName>UNITED KINGDOM</TerritoryName> 
     </Assignment> 
    </ns1:LeadAssigned> 
    </LeadXml> 
    <AuthenticationUsername>Username</AuthenticationUsername> 
    <AuthenticationPassword>Password</AuthenticationPassword> 
</ConsumeLeadRequest> 

LINQ pour XML Comment naviguer aux éléments?

Merci Sp

J'ai essayé quelques petites choses comme

XDocument Leads = XDocument.Load(@"C:\Users\Steven.Pentleton\AppData\Local\Temporary Projects\PAALeadImport\PAAExmple.xml"); 
     var Lead = (from L in Leads.Descendants("Lead") 
        select new { LeadType = (string)L.Element("Reference") }).ToList(); 
     var S = Lead.First(); 
     string T = S.LeadType; 
+1

Qu'est-ce que vous avez essayé jusqu'à présent? Pouvez-vous nous montrer ce que vous avez fait? – Philippe

+0

J'ai mis à jour la question Merci – Steven

+1

Qu'est-ce que vous cherchez? – anishMarokey

Répondre