2
我有這樣的XML文檔:LINQ到XML用的XDocument命名空間問題
<?xml version="1.0" encoding="utf-8"?>
<directoryresponse xmlns="https://www.sisow.nl/Sisow/REST" version="1.0.0">
<directory>
<issuer>
<issuerid>01</issuerid>
<issuername>ABN Amro Bank</issuername>
</issuer>
<issuer>
<issuerid>02</issuerid>
<issuername>ASN Bank</issuername>
</issuer>
</directory>
</directoryresponse>
而且這不起作用:
var banks = doc.Descendants("issuer").Select(x =>
new Bank(Convert.ToInt32(x.Element("issuerid").Value), x.Element("issuername").Value)).ToList();
但是,當我手動去除directoryresponse XML命名空間 xmlns="https://www.sisow.nl/Sisow/REST"
它作品!命名空間網址是。那麼爲什麼xdoc
如果它是404則不會忽略名稱空間?
這也不起作用:var banks = doc.Elements().Where(e => e.Name.LocalName == "issuer").Select(...
的主要問題是:我怎麼能修改我的代碼,以便它忽略了404命名空間?