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);
                }
             
            }
    做个快乐的自己。
  • 相关阅读:
    2019重新起航:搭建个人博客
    Alibaba Nacos:搭建Nacos平台
    ELK:使用docker搭建elk平台
    SpringBoot:关于默认连接池Hikari的源码剖析
    git常用命名:自用,持续更新
    linux常用命名汇总:自用,持续更新
    升级项目版本:SpringBoot1.5.x到SpringBoot2.0.x
    Python学习第十五课——类的基本思想(实例化对象,类对象)
    Python学习第十三课——re(正则表达式)模块
    Python学习第十四课——面向对象基本思想part1
  • 原文地址:https://www.cnblogs.com/Jessy/p/2319237.html
Copyright © 2011-2022 走看看