• 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);
                }
             
            }
    做个快乐的自己。
  • 相关阅读:
    如何提高代码质量(管理篇):代码复查
    Codeforce 239 B. Easy Tape Programming
    Codeforces Round #530 (Div. 1) 1098A Sum in the tree
    Codeforce 1098-A
    8月5日加油吧,菜鸡
    8月5日训练日记
    疯子的算法总结(七) 字符串算法之 manacher 算法 O(N)解决回文串
    疯子的算法总结(六) 复杂排序算法 ① 归并排序 merge_sort()
    疯子的算法总结(五) 矩阵乘法 (矩阵快速幂)
    疯子的算法总结(四)贪心算法
  • 原文地址:https://www.cnblogs.com/Jessy/p/2319237.html
Copyright © 2020-2023  润新知