난 당신이 조금 명확히 함께 할 수 있다고 생각하지만, 그래도 공급 업체가 공급 업체 섹션의 키해야 이름을 속성 가정 원하는 효과를 달성
,882,485,184 : 당신은
XDocument xml = XDocument.Load("path to your xml file");
var dict = xml.Descendants("Vendors")
.Elements()
.ToDictionary(r => r.Attribute("name").Value, r => r.Value);
XML 구조를 가정 명확하지 않은
그러나 나는 잘못된 접근 방식을 사용하고 있다고 생각합니다.
public class Vendor
{
public Vendor()
{ }
public string CustRef { get; set; }
public string VendorName { get; set; }
public string InvP { get; set; }
}
그리고 쿼리가 될 것입니다 : 더 나은 아이디어는 예를 들어,이 정보를 저장하는 사용자 정의 유형 Vendor
을 생성하는 것입니다 당신에게보고 Vendor
의 목록을 줄 것이다
var query = (from n in xml.Descendants("Vendors")
select new Vendor()
{
VendorName = n.Element("Vendor").Attribute("name").Value,
CustRef = n.Descendants("Vendor").Select(x => x.Element("CustRef").Value).SingleOrDefault(),
InvP = n.Descendants("Vendor").Select(x => x.Element("InvP").Value).SingleOrDefault()
}).ToList();
같은 :
이제 데이터로 작업하기가 훨씬 쉽다.
시도해 보셨습니까? –
사전 키는 무엇이고 사전 값은 무엇입니까? – rajeemcariazo
@rajeem_cariazo KEY - 공급 업체 VALUE - bankRed .... KEY - CustRef VALUE - dfas16549464 .... KEY InP VALUE - 1,12 – user1358072