如何使用 LINQ 获取肥皂请求中的方法名称和命名空间?

发布于 2024-08-08 13:29:59 字数 1662 浏览 4 评论 0原文

如何使用 LINQ to XML 从此 xml 中提取方法名称和命名空间?

<?xml version="1.0" encoding="utf-8"?>
<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"
  xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <soap:Header>
    <wsa:Action>http://www.webserviceX.NET/GetISOCountryCodeByCountyName</wsa:Action>
    <wsa:MessageID>urn:uuid:047f0012-b7d2-408d-bdd7-aa556edf70e8</wsa:MessageID>
    <wsa:ReplyTo>
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsa:To>    </wsa:To>
    <wsse:Security>
      <wsu:Timestamp wsu:Id="Timestamp-2a4072a3-338c-434a-90ff-5f7d0aa6acbc">
        <wsu:Created>2009-10-22T19:20:22Z</wsu:Created>
        <wsu:Expires>2009-10-22T19:25:22Z</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
  </soap:Header>
  <soap:Body>
    <GetISOCountryCodeByCountyName xmlns="http://www.webserviceX.NET">
      <CountryName>India</CountryName>
    </GetISOCountryCodeByCountyName>
  </soap:Body>
</soap:Envelope>

我需要获取值 GetISOCountryCodeByCountyName 和 http://www.webserviceX.NET

How to extract method name and namespace from this xml using LINQ to XML?

<?xml version="1.0" encoding="utf-8"?>
<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"
  xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <soap:Header>
    <wsa:Action>http://www.webserviceX.NET/GetISOCountryCodeByCountyName</wsa:Action>
    <wsa:MessageID>urn:uuid:047f0012-b7d2-408d-bdd7-aa556edf70e8</wsa:MessageID>
    <wsa:ReplyTo>
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsa:To>    </wsa:To>
    <wsse:Security>
      <wsu:Timestamp wsu:Id="Timestamp-2a4072a3-338c-434a-90ff-5f7d0aa6acbc">
        <wsu:Created>2009-10-22T19:20:22Z</wsu:Created>
        <wsu:Expires>2009-10-22T19:25:22Z</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
  </soap:Header>
  <soap:Body>
    <GetISOCountryCodeByCountyName xmlns="http://www.webserviceX.NET">
      <CountryName>India</CountryName>
    </GetISOCountryCodeByCountyName>
  </soap:Body>
</soap:Envelope>

I need to get the value GetISOCountryCodeByCountyName and http://www.webserviceX.NET

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2024-08-15 13:29:59
public static void ReadXmlUsingLinq()
{
            XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><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\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"><soap:Header><wsa:Action>http://www.webserviceX.NET/GetISOCountryCodeByCountyName</wsa:Action><wsa:MessageID>urn:uuid:047f0012-b7d2-408d-bdd7-aa556edf70e8</wsa:MessageID><wsa:ReplyTo><wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address></wsa:ReplyTo><wsa:To>   </wsa:To><wsse:Security><wsu:Timestamp wsu:Id=\"Timestamp-2a4072a3-338c-434a-90ff-5f7d0aa6acbc\"><wsu:Created>2009-10-22T19:20:22Z</wsu:Created><wsu:Expires>2009-10-22T19:25:22Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><GetISOCountryCodeByCountyName xmlns=\"http://www.webserviceX.NET\"><CountryName>India</CountryName></GetISOCountryCodeByCountyName></soap:Body></soap:Envelope>");

            var query = from XmlNode a in xdoc.DocumentElement where a.Name == "soap:Body" select a.FirstChild;
            foreach (XmlNode node in query)
            {
                Console.WriteLine(node.Name);
                Console.WriteLine(node.Attributes["xmlns"].Value);
            }
            Console.ReadLine();
}
public static void ReadXmlUsingLinq()
{
            XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><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\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"><soap:Header><wsa:Action>http://www.webserviceX.NET/GetISOCountryCodeByCountyName</wsa:Action><wsa:MessageID>urn:uuid:047f0012-b7d2-408d-bdd7-aa556edf70e8</wsa:MessageID><wsa:ReplyTo><wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address></wsa:ReplyTo><wsa:To>   </wsa:To><wsse:Security><wsu:Timestamp wsu:Id=\"Timestamp-2a4072a3-338c-434a-90ff-5f7d0aa6acbc\"><wsu:Created>2009-10-22T19:20:22Z</wsu:Created><wsu:Expires>2009-10-22T19:25:22Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><GetISOCountryCodeByCountyName xmlns=\"http://www.webserviceX.NET\"><CountryName>India</CountryName></GetISOCountryCodeByCountyName></soap:Body></soap:Envelope>");

            var query = from XmlNode a in xdoc.DocumentElement where a.Name == "soap:Body" select a.FirstChild;
            foreach (XmlNode node in query)
            {
                Console.WriteLine(node.Name);
                Console.WriteLine(node.Attributes["xmlns"].Value);
            }
            Console.ReadLine();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文