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);


            }
  • 相关阅读:
    Docker入门之docker-compose [转]
    防火墙和iptables
    MariaDB/MySQL备份和恢复(三):xtrabackup用法和原理详述
    Veritas NetBackup™ for VMware 介绍 (NBU版本 8.2)
    RMAN备份恢复所需要了解的Oracle术语
    mac 下使用命令行打开项目
    ORACLE 11g RAC-RAC DG Duplicate 搭建(生产操作文档)
    15-vuex
    14-Promise
    13-vue-router2
  • 原文地址:https://www.cnblogs.com/evlon/p/1408753.html
Copyright © 2011-2022 走看看