zoukankan      html  css  js  c++  java
  • 加载有命名空间,但没有声名的XML

            public static void Sample1()
            { 
                    String xmlString 
    = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
        <soapenv:Header>
            <tns:RequestSOAPHeader xmlns:tns=""http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1"">
                <tns:spId>22220001</tns:spId>
                <tns:spPassword>79A0FFF9D8CDC73F42691ABA88EB1195</tns:spPassword>
            </tns:RequestSOAPHeader>
        </soapenv:Header>
        <soapenv:Body>
            <ns2:sendSms xmlns:ns2=""http://www.chinatelecom.com.cn/schema/ctcc/sms/send/v2_1/local"">
                <ns2:addresses>tel:+8613156111754</ns2:addresses>
                <ns2:message>hello world</ns2:message>
            </ns2:sendSms>
        </soapenv:Body>
    </soapenv:Envelope>
    ";

                    XmlDocument xml 
    = new XmlDocument();
                    xml.LoadXml(xmlString);

                    Console.WriteLine(xml.DocumentElement.Name);
            }

            
    public static void Sample2()
            {
                String xmlString 
    = @"<soapenv:Envelope>
        <soapenv:Header>
            <tns:RequestSOAPHeader>
                <tns:spId>22220001</tns:spId>
                <tns:spPassword>79A0FFF9D8CDC73F42691ABA88EB1195</tns:spPassword>
            </tns:RequestSOAPHeader>
        </soapenv:Header>
        <soapenv:Body>
            <ns2:sendSms>
                <ns2:addresses>tel:+8613156111754</ns2:addresses>
                <ns2:message>hello world</ns2:message>
            </ns2:sendSms>
        </soapenv:Body>
    </soapenv:Envelope>
    ";

                NameTable nt 
    = new NameTable();
                XmlNamespaceManager nsmgr 
    = new XmlNamespaceManager(nt);
                nsmgr.AddNamespace(
    "soapenv""http://schemas.xmlsoap.org/soap/envelope/");
                nsmgr.AddNamespace(
    "tns""http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1");
                nsmgr.AddNamespace(
    "ns2""http://www.chinatelecom.com.cn/schema/ctcc/sms/send/v2_1/local");

                XmlParserContext context 
    = new XmlParserContext(nt, nsmgr,  null,  XmlSpace.None);

                XmlDocument xml 
    = new XmlDocument();
                
    // Create the reader.
                using (XmlTextReader reader = new XmlTextReader(xmlString, XmlNodeType.Element, context))
                {
                    xml.Load(reader);
                }

                Console.WriteLine(xml.DocumentElement.Name);


            }
  • 相关阅读:
    实用小软件
    没有找到MSVCP71.dll,迅雷5无法进行离线下载,P2P Seacher无法连入emule网络
    PSP2000V3版5.03系统误删PSP文件夹的拯救方案
    图书馆图书检索的小技巧
    thinkpad指点杆(trackpoint)在WPS的word文档中失效的解决办法
    笔记本电池死而复生
    调试Page.IsPostBack,感觉好奇怪
    OleDbSchemaGuid.Columns返回DataTable介绍
    静态类生命周期的问题
    IE中居中,FF中出问题
  • 原文地址:https://www.cnblogs.com/evlon/p/1408753.html
Copyright © 2011-2022 走看看