zoukankan      html  css  js  c++  java
  • XML解析

    下面是xml解析的代码:

     private void readEnvelope(string str)
            {
            

                // <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body 

                
    //xmlns:amp="http://schemas.altigen.com/mobility/"><amp:Session>c2lwOmtpbm8uc29uZ0BtY3MuY29tO29wYXF1ZT11c2VyOmVwaWQ6VEJsMkNHVlRmMS1TZ05HS

                
    //DFJMFhoQUFBO2dydXU</amp:Session><amp:ConferenceUpdate sequenceId="23628" type="2" version="1.0">
                
    //<ConfID>41869784-3b1d-4619-af5d-

                
    //96253c5f7bf0</ConfID><State>6</State>
                
    //<Members type="Line">

                 
    //<Member><ID>kino.song@mcs.com</ID><Address>sip:kino.song@mcs.com</Address>
                
    //<Display>Kino Song</Display>
                
    //</Member>

                
    //<Member><ID>ocsuser360@mcs.com</ID><Address>sip:ocsuser360@mcs.com</Address>
                
    //</Member>
                
    //<Member><ID>yvonehu@mcs.com
                
    //</ID><Address>sip:yvonehu@mcs.com</Address><Display>yvone 
                
    //hu</Display></Member>

                
    //</Members>
                
    //</amp:ConferenceUpdate></soap:Body></soap:Envelope>


                try
                {
                    XDocument doc = XDocument.Parse(str);

                    XElement conferenceUpdateRespElement = doc.Descendants(amp + "ConferenceUpdate").FirstOrDefault();

                    if (conferenceUpdateRespElement == null)
                    {
                        //not a conference update event
                        return;
                    }

                    updated = true;

                    this._confId = XMLUtils.TryGetElementValue(conferenceUpdateRespElement, "ConfID""");

                    this._conferenceState = XMLUtils.TryGetElementValue(conferenceUpdateRespElement, "State""");

                    int.TryParse(XMLUtils.TryGetElementAttribute(conferenceUpdateRespElement, "sequenceId"string.Empty), out this._sequenceId);

                    string type = XMLUtils.TryGetElementAttribute(conferenceUpdateRespElement, "type"string.Empty);

                    XElement membersElement = conferenceUpdateRespElement.Descendants("Members").FirstOrDefault();

                    string memberType = XMLUtils.TryGetElementAttribute(membersElement, "type"string.Empty);

                    this._memberLine = string.Equals(memberType, "type", StringComparison.CurrentCultureIgnoreCase);

                    var memberElements = membersElement.Descendants("Member");

                    List<CLID> members = new List<CLID>();

                    if (this._memberLine)
                    {
                        foreach (var item in memberElements)
                        {
                            _participants.Add(
                                  new CLID(
                                  XMLUtils.TryGetElementValue(item, "ID""UnKnow"),
                                  XMLUtils.TryGetElementValue(item, "Address""UnKnow"),
                                  XMLUtils.TryGetElementValue(item, "Display""UnKnow")
                                    ));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.e(ex.Message, ex);
                }
             
            }
    做个快乐的自己。
  • 相关阅读:
    ES6数组的扩展--Array.from()和Array.of()
    前端面试中的各种方法实现
    理解 JavaScript call()/apply()/bind()
    【前端面试】变量和类型计算
    Kubernetes1.3新特性:支持GPU
    撸了一个微信小程序项目
    微信开发(调用各种接口)
    Android 神兵利器之通过解析网页获取到的API数据合集,可拿来就用
    Kubernetes1.4正式发布
    Kubernetes1.4即将发布
  • 原文地址:https://www.cnblogs.com/Jessy/p/2319237.html
Copyright © 2011-2022 走看看