특성과 하위 항목이 모두있는 노드를 구문 분석하는 데 어려움을 겪고 있습니다.노드 아래에 여러 속성 값 가져 오기
고객 노드에 들어가서 그 아래의 모든 것을 웹 페이지에서 사용할 값으로 파싱해야합니다.
var contacts = from c in xdoc.Descendants("contact")
select new Contact
{
Email = (string)c.Element("email"),
HomePhone = (string)c.Element("phone").Attribute("type") // ?
};
그리고 내 XML :
<customer>
<contact>
<name part="first">Rick</name>
<name part="last">Smith</name>
<email>[email protected]</email>
<phone type="home">2299998989</phone>
<phone type="work">2298887878</phone>
<phone type="cell">2297778878</phone>
<address type="home">
<street line="1">4001 Coleman Rd</street>
<street line="2">Ste. 99</street>
<city>Tempe</city>
<regioncode>AZ</regioncode>
<postalcode>43444</postalcode>
</address>
</contact>
<comments>Customer comments</comments>
</customer>
<vendor>
<contact>
<name part="full" type="salesperson">Joe Smith</name>
</contact>
</vendor>
어떤 오류가 발생 했습니까? 귀하의 코드는 괜찮아 보인다. 단지 불완전하다. – Tilak