xmlファイルを読み込もうとしています。これは私がしました:
from e in XDocument.Load(stream).Root.Elements("cust")
select new Customer
{
MemeberID = (int)e.Attribute("custid"),
CustomerID = (int)e.Attribute("custid"),
FirstName = (string)e.Attribute("fname"),
LastName = (string)e.Attribute("lname"),
ShowsNumber = (int)e.Attribute("count_noshow"),
VisitNumber = (int)e.Attribute("count_resos"),
Cancellation = (int)e.Attribute("count_cancel"),
MobileNumber = (string)e.Element("phone").Attribute("phonenumber")
})
うまく機能していましたが、xmlドキュメントにmobilenuber
属性を含める必要がない状況になりました。xmlノードにこの携帯電話番号がなかった場合、デフォルト値を設定できますか?
どうもありがとう
属性は不要です:
MobileNumber = (string)e.Element("phone").Attribute("phonenumber") ?? defaultValue
不要な要素:
MobileNumber = e.Element("phone") != null ? (string)e.Element("phone").Attribute("phonenumber") : defaultValue
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加