我一直在從Scott Allen的Puralsight course on Linq Fundamentals開始工作,此鏈接部分描述了使用命名空間前綴讀取xml,但我無法完成此工作。Linq到名稱空間前綴不起作用的XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<OutboundEvent
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:abb.com:assetsuite:IF:Event http://apifw/devifa/xml/GeneralLedger/GeneralLedger.Publish.Event.V940.xsd"
xmlns="urn:abb.com:assetsuite:IF:Event"
xmlns:hdr="urn:abb.com:assetsuite:IF:Header"
xmlns:bo="urn:abb.com:assetsuite:IF:BO"
xmlns:boe="urn:abb.com:assetsuite:IF:IFExtension"
>
...
<bo:BusinessObject>
...
</bo:BusinessObject>
</OutboundEvent>
我應該得到一個單一的XElement從下面的代碼返回,但我並不:
var document = XDocument.Load(path);
var bo = (XNamespace)"urn:abb.com:assetsuite:IF:BO";
var businessobjects =
from elements in document.Element("OutboundEvent")?.Elements(bo + "BusinessObject")
?? Enumerable.Empty<XElement>()
select elements;
請勿截取_text _...後的實際文字。 –
粘貼跨越多頁的XML的最佳方式是什麼? – CodenameCain
粘貼XML的相關部分,它不需要是全文。足以說明問題。 –