I’ve got a problem with XPathSelectElement while reading some xml-lines….
the function handleEachSession is called two times from the mathod childList.ForEach() from my other function:
private void handleMonitorResponse(XElement receivedSessions)
{
List<XElement> childList = receivedSessions.Elements().ToList();
childList.ForEach(handleEachSession);
childList has two elements (two XML lines, those i want it to have)
Then i can see in the Debugger that both calls of handleEachSession() gets the right XElement session. Those two i want it to have.
Now there are these XPathSelectElement’s. It works for the first call but not for the second.
Second time i get the new XElement session, but XPathSelectElement still Returns the old values from the first call.
Hum!?? I cant understand this behavior.
private void handleEachSession(XElement session)
{
XElement receivedSessionId = session.XPathSelectElement("//sessionId");
XElement receivedQuality = session.XPathSelectElement("//quality");
XElement receivedContentStatus = session.XPathSelectElement("//contentStatus");
…
Can anyone please help me?
The XMLs are:
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>
according to the xpath-syntax, the double slash (//) means: Selects nodes in the document from the current node that match the selection no matter where they are.
so with that in mind, you probably have to change your
handleEachSessionfunction as