从query-xml到API选择单个节点

时间:2013-07-22 20:07:44

标签: c# xml api sdk

我以前使用xml文件实现了这个:

XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("fileString.xml");

我正在使用的query-xml连接到API并返回结果,但是我在选择单个节点时遇到问题,因为xml不是文件,因此以前的方式不起作用。

有没有人知道如何使用query-xml实现这一目标?

代码是:`const string hostname =“ * ”;             const string username =“ ** ”;             const string password =“ ** ”;

        ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

        var client = new InformationServiceClient("BasicHttpBinding_InformationService",
                                                  string.Format("https://{0}:17778/SolarWinds/InformationService/OrionBasic", hostname));
        client.ClientCredentials.UserName.UserName = username;
        client.ClientCredentials.UserName.Password = password;
        client.Open();

        var result = client.QueryXml("SELECT TOP 1 A.AlertDefID, I.Status, I.Node, A.ActiveObject, A.ObjectType, A.Acknowledged, A.AcknowledgedBy, A.AcknowledgedTime, A.TriggerTimeOffset, A.TriggerTimeStamp FROM Orion.AlertStatus A INNER JOIN Orion.Interface I ON A.ID = I.ID WHERE A.Acknowledged = 0 RETURN XML AUTO", null);
        `

1 个答案:

答案 0 :(得分:0)

您是否只需要将字符串加载到xml文档中?

您可以执行以下操作...

var xml = new XmlDocument();
xml.LoadXml(xmlString);