我很难解析同时具有属性和后代的节点。
我需要进入客户节点并将其下方的所有内容解析为在网页上使用的值。
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>rick@yahoo.com</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>