程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c# 操作帶名稱空間的xml文件

c# 操作帶名稱空間的xml文件

編輯:C#入門知識

xml文件如下:
[html]
<?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

[csharp]
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); 

作者:wangxianshou
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved