我尝试使用C#获取子节点的XElement值。 XElement块如下。我的目的是在'c0'节点获取值。我怎么能这样做?
// client is Orion SDK (SWIS) client.
XElement xe = client.QueryXml("select Uri FROM Orion.Pollers WHERE NetObjectID = 15", null);
XElement结果块:
<queryResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.solarwinds.com/2007/08/informationservice">
<template>
<resultset>
<column name="Uri" type="String" ordinal="0" />
</resultset>
</template>
<data>
<row>
<c0>swis://solarwinds./Orion/Orion.Pollers/PollerID=55</c0>
</row>
<row>
<c0>swis://solarwinds./Orion/Orion.Pollers/PollerID=56</c0>
</row>
<row>
<c0>swis://solarwinds./Orion/Orion.Pollers/PollerID=57</c0>
</row>
<row>
<c0>swis://solarwinds./Orion/Orion.Pollers/PollerID=58</c0>
</row>
</data>
</queryResult>
答案 0 :(得分:0)
我找到了解决方案。代码块如下。
XElement xe = client.QueryXml("SELECT Uri FROM Orion.Pollers WHERE NetObjectID = 15", null);
IList<XElement> indexedElements = xe.Elements().ToList();
foreach (var item in ((XElement)xe.Elements().ToList()[1]).Elements().ToList())
{
try
{
//Do something with
//item.Value
}
catch (Exception exc)
{
throw exc;
}
}