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


            }
  • 相关阅读:
    算数基本定理与质因数分解
    质数的两种筛法
    质数及其判法
    二十二、Spring MVC与Structs2的区别总结
    二十一、MVC的WEB框架(Spring MVC)
    二十、MVC的WEB框架(Spring MVC)
    十九、Spring框架(注解方式测试)
    十八、Spring框架(AOP)
    十七、Spring框架(IOC/DI)
    创建型模式篇(建造者模式Builder Pattern)
  • 原文地址:https://www.cnblogs.com/evlon/p/1408753.html
Copyright © 2011-2022 走看看