1
flow.Name肯定等於flowData XDocument中某個流的「名稱」。xdocument.root.element和其他排列返回null
XElement rootelem = flowData.Root.Element("flows");
上述行rootelem包含流元素,它是兒童預期,但下面的行拋出一個空引用異常後,爲什麼呢?
flowData.Root.Element(flow.Name).Remove();
flowData被聲明爲的XDocument,看起來像這樣:
<?xml version="1.0" encoding="UTF-8"?>
-<D53ESB>
-<comms>
<diagnosticemails sender="eventlog"/>
</comms>
-<globalparams>
<!-- some comments... -->
</globalparams>
-<flows>
-<flow webserviceonly="false" stoponerror="true" name="testFlow">
-<action name="t1">
<schedule firsttime="01/01/2014 14:10:00" every="600000"/>
-<adapter name="GetXml">
<param name="url" value="http://xml.betfred.com/Football-Championship.xml"/>
</adapter>
</action>
</flow>
...more flows
</flows>
</D53ESB>
這兩行返回null太:
var xelem2 = flowData.Root.Element(flow.Name);
var xelem3 = flowData.Root.Element("flows").Element(flow.Name);
而這兩個返回空集:
var keepgoing = new XDocument(rootelem.Descendants(flow.Name));
var idk = new XDocument(flowData.Descendants(flow.Name));
天上!這有用,謝謝! – Jimmy