아래의 XML 스 니펫은 훨씬 더 큰 XML의 일부입니다. 나는 주소 1, 2, 3 및 도시와 주, 우편 번호 및 국가를 얻기 위해 계속해서 노력해 왔습니다. 내가 이것을 구체화 할 수 있도록 기능화하고 싶습니다. 그러나 InvoiceHeader id = "XXXX"를 기반으로하는 주소이지만 벽을 계속 뛰어 다니고 있습니다. 아래의 쿼리를 사용하여 줄을 따라 가봤지만 오류가 계속 발생합니다. 개체 참조가 개체 인스턴스로 설정되지 않았습니다.Linq를 XML로 가져 오기 xml 부분 검색
여기 내 검색어입니다 누군가 내 명백한 실수를 지적하시기 바랍니다 수 있습니다.
IEnumerable<string> partNos =
from item in PurchaseOrderXml.Descendants("RemitTo").Descendants("Address")
where (string)item.Attribute("id").Value == "23951768"
select (string)item;
<Invoice>
<InvoiceHeader id="23951768" status="InProcess">
<InvoiceName />
<InvoiceNumber>23951768</InvoiceNumber>
<InvoiceDate>2014-09-26 00:00:00.0</InvoiceDate>
<DueDate>2014-10-26 00:00:00.0</DueDate>
<SupplierInvoiceNo>534254504</SupplierInvoiceNo>
<InvoiceType>Invoice</InvoiceType>
<Supplier id="3825405">
<ContactInfo type="main">
<Address>
<AddressLine lineNumber="1">Post </AddressLine>
<AddressLine lineNumber="2">30 Street</AddressLine>
<AddressLine lineNumber="3">30 Street</AddressLine>
<City>Saint Louis</City>
<State>MO</State>
<PostalCode>63103-2530</PostalCode>
<Country isoCountryCode="US">United States</Country>
</Address>
</ContactInfo>
</Supplier>
<BillTo>
<Address>
<AddressLine lineNumber="1">vvvv</AddressLine>
<AddressLine lineNumber="2">vvvv</AddressLine>
<City>Philadelphia</City>
<State>PA</State>
<PostalCode>19222</PostalCode>
<Country isoCountryCode="US">United States</Country>
</Address>
</BillTo>
<RemitTo>
<Address>
<AddressLine lineNumber="1">P O BOX 535182</AddressLine>
<AddressLine lineNumber="2" />
<AddressLine lineNumber="3" />
<City>ATLANTA</City>
<State>GA</State>
<PostalCode>303535182</PostalCode>
<Country isoCountryCode="US">United States</Country>
</Address>
</RemitTo>
</InvoiceHeader>
</Invoice>
그래서 두 건의 질의가 필요합니까? – Miguel
예제를 제공하기 위해 업데이트 하겠지만 개념적으로는 두 개의 쿼리가 필요합니다. –
예를 들어 주시면 감사하겠습니다. 나는 물고기를 배우려고 노력하고있다 : - D. – Miguel