在阅读一些 xml 行时,我遇到了 XPathSelectElement 的问题......
函数 handleEachSession 从我的另一个函数的 mathod childList.ForEach() 调用了两次:
private void handleMonitorResponse(XElement receivedSessions)
{
List<XElement> childList = receivedSessions.Elements().ToList();
childList.ForEach(handleEachSession);
childList 有两个元素(两条 XML 行,我希望它有) 然后我可以在调试器中看到,handleEachSession() 的两个调用都获得了正确的 XElement 会话。这两个我想要它。
现在有了这些 XPathSelectElement。它适用于第一次通话,但不适用于第二次通话。第二次我得到新的 XElement 会话,但 XPathSelectElement 仍然返回第一次调用的旧值。哼!??我无法理解这种行为。
private void handleEachSession(XElement session)
{
XElement receivedSessionId = session.XPathSelectElement("//sessionId");
XElement receivedQuality = session.XPathSelectElement("//quality");
XElement receivedContentStatus = session.XPathSelectElement("//contentStatus");
…
谁能帮帮我吗?
XML 是:
receivedSessions =
<sessions type="array">
<item type="object">
<sessionId type="string">8c86716a87</sessionId>
<quality type="string">mid</quality>
<addressUri type="string">http://192.168.6.234/media/SorrowPinkFloyd_.mp4</addressUri>
<currentTime type="number">1.5542887</currentTime>
<contentStatus type="string">paused</contentStatus>
</item>
<item type="object">
<sessionId type="string">c795067c4e</sessionId>
<quality type="string">mid</quality>
<addressUri type="string">http://192.168.6.234/media/trailer.mp4</addressUri>
<currentTime type="number">3.3492105</currentTime>
<contentStatus type="string">playing</contentStatus>
</item>
</sessions>
session = (first call)
<item type="object">
<sessionId type="string">8c86716a87</sessionId>
<quality type="string">mid</quality>
<addressUri type="string">http://192.168.6.234/media/SorrowPinkFloyd_.mp4</addressUri>
<currentTime type="number">1.5542887</currentTime>
<contentStatus type="string">paused</contentStatus>
</item>
session = (second call)
<item type="object">
<sessionId type="string">c795067c4e</sessionId>
<quality type="string">mid</quality>
<addressUri type="string">http://192.168.6.234/media/trailer.mp4</addressUri>
<currentTime type="number">3.3492105</currentTime>
<contentStatus type="string">playing</contentStatus>
</item>