0

大家好,我下面这个 xml 肥皂响应来自 web 服务,我需要的是在“IncomingApplications”父节点下获取处理类型 = 1 的 xmlnodelist,我已经通过使用下面的代码获得了所有“IncomingApplications”的 xmlnodelist

  XmlNodeList xmlnode = xmlDoc.DocumentElement.SelectNodes("//soap:Body/descendant::*[name()='IncomingApplications']", nsmgr);

现在我想更改上面的xpath,使其返回其子节点即 TreatmentType = 1 的 IncomingApplications 节点,请问如何更改 xpath 以获得结果?

 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetIncomingApplicationsDataResponse xmlns="http://test.com/webservices/service">
      <GetIncomingApplicationsDataResult>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <InDataSet xmlns="http://test.com/webservices/xyzConfigWS/InDataSet.xsd">
            <IncomingApplications diffgr:id="InApp1" msdata:rowOrder="0">
              <SiteName>Test</SiteName>
              <QueueId>1501</QueueId>
              <ApplicationId>3362546</ApplicationId>
              <CountryId>1</CountryId>
              <HoldingQueueId>33625460</HoldingQueueId>
              <CallbackQueueId>3366025</CallbackQueueId>
              <TreatmentType>0</TreatmentType>
              <UnderThresholdQueueId>33625460</UnderThresholdQueueId>
              <IVRGroup>IVR</IVRGroup>
            </IncomingApplications>
            <IncomingApplications diffgr:id="InApp2" msdata:rowOrder="1">
              <SiteName>Test</SiteName>
              <QueueId>1501</QueueId>
              <ApplicationId>3362600</ApplicationId>
              <CountryId>1</CountryId>
              <HoldingQueueId>33626000</HoldingQueueId>
              <CallbackQueueId>3366025</CallbackQueueId>
              <TreatmentType>0</TreatmentType>
              <UnderThresholdQueueId>33626000</UnderThresholdQueueId>
              <IVRGroup>IVR</IVRGroup>
            </IncomingApplications>
            <IncomingApplications diffgr:id="InApp3" msdata:rowOrder="2">
              <SiteName>Test</SiteName>
              <QueueId>1501</QueueId>
              <ApplicationId>3362769</ApplicationId>
              <CountryId>1</CountryId>
              <HoldingQueueId>33627690</HoldingQueueId>
              <CallbackQueueId>3366025</CallbackQueueId>
              <TreatmentType>1</TreatmentType>
              <UnderThresholdQueueId>33627690</UnderThresholdQueueId>
              <IVRGroup>IVR</IVRGroup>
            </IncomingApplications>
        </diffgr:diffgram>
      </GetIncomingApplicationsDataResult>
    </GetIncomingApplicationsDataResponse>
  </soap:Body>
</soap:Envelope>
4

1 回答 1

0

从其他论坛得到答案,这是使用 linq to xml 而不是 xpath 的解决方案

XDocument xDoc = XDocument.Load("SampleFile.xml");

字符串 nameSpaceToSearch = @" http://test.com/webservices/xyzConfigWS/InDataSet.xsd "; var result = (from xElement in xDoc.Descendants(XName.Get("IncomingApplications", nameSpaceToSearch)) where xElement.Element(XName.Get("TreatmentType", nameSpaceToSearch)).Value == "1" select xElement);

于 2013-11-27T13:49:58.377 回答