下面是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);
}
}
{
// <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);
}
}