c# 操作带名称空间的xml文件

3 篇文章 0 订阅
xml文件如下:

<?xml version = "1.0" ?>
<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/03/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>urn:SumMtoN</wsa:Action>
    <wsa:MessageID>uuid:88dbfb0a-0b8c-470d-a0cf-5716e3f6f117</wsa:MessageID>
    <wsa:ReplyTo>
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsa:To>http://localhost:2000/axis2/services/WS_rampart3</wsa:To>
    <wsse:Security soap:mustUnderstand="1">
      <wsu:Timestamp wsu:Id="Timestamp-f9782b0b-dc61-4926-a8e9-d90da4b3a259">
        <wsu:Created>2012-06-30T03:04:08Z</wsu:Created>
        <wsu:Expires>2012-06-30T03:09:08Z</wsu:Expires>
      </wsu:Timestamp>
      <wsse:UsernameToken>
        <wsse:Username>axis2</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">rampart</wsse:Password>
        <!--<wsse:Nonce>uv++05ae3bvoziMQfTTG/w==</wsse:Nonce>-->
      </wsse:UsernameToken>
    </wsse:Security>
  </soap:Header>
  <soap:Body>
    <SumMtoN xmlns="http://service.rampart.tutorial">
      <x>1</x>
      <y>100</y>
    </SumMtoN>
  </soap:Body>
</soap:Envelope>

c#代码获取【wsse:UsernameToken】Xmlelement

XmlDocument doc = new XmlDocument();
doc.Load(@"C:\Documents and Settings\10015042\My Documents\Visual Studio Projects\Webservice\Webservice\SOAP.xml");

				
XmlNamespaceManager nm = new XmlNamespaceManager(doc.NameTable);
nm.AddNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");
nm.AddNamespace("wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

XmlNode xn = doc.SelectSingleNode("/soap:Envelope/soap:Header/wsse:Security/wsse:UsernameToken",nm);
XmlElement ele = (XmlElement)xn;
MessageBox.Show(ele.OuterXml);




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值