C# - 解析 Soap 响应以提取数据

我是 C# Soap Web 服务的新手。我可以提出肥皂请求。但不确定如何解析下面的肥皂响应以获取 OrderId 例如。


<?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">

    <soap:Body>

        <OrderCreateByChannelResponse

            xmlns="http://retailexpress.com.au/">

            <OrderCreateByChannelResult>

                <Response

                    xmlns="">

                    <OrderCreate>

                        <Customer>

                            <Result>Success</Result>

                            <ExternalCustomerId>170</ExternalCustomerId>

                            <CustomerId>300941</CustomerId>

                        </Customer>

                        <Order>

                            <Result>Success</Result>

                            <ExternalOrderId>INT_3673_ccv_20190926132240</ExternalOrderId>

                            <OrderId>19-00033544</OrderId>

                            <ChannelID>1</ChannelID>

                        </Order>

                        <OrderItems>

                            <OrderItem>

                                <Result>Success</Result>

                                <ExternalOrderItemId></ExternalOrderItemId>

                                <ProductId>126659</ProductId>

                                <OrderId>19-00033544</OrderId>

                            </OrderItem>

                        </OrderItems>



MYYA
浏览 84回答 1
1回答

缥缈止盈

尝试这样XDocument doc = XDocument.Parse(testXML1);XNamespace ns = doc.Root.GetDefaultNamespace();string ExternalCustomerId="";&nbsp; &nbsp;&nbsp;string CustomerId="";&nbsp;foreach (XElement element in doc.Descendants(ns + "ExternalCustomerId"))&nbsp;{&nbsp; &nbsp;ExternalCustomerId = element.Value;&nbsp;}&nbsp;foreach (XElement element in doc.Descendants(ns + "CustomerId"))&nbsp;{&nbsp; &nbsp;CustomerId = element.Value;&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP