我是非常新的XML使用C#我有一個XML我需要通過父母的具體子女 我需要獲取id和調用變量變量我做到了這一點,但每次都沒有通過循環C#中的後代沒有給出正確的值
我是否需要通過所有的父母的xml,直到我得到了我想要的樹?
的XML
<message xmlns="jabber:client" to="[email protected]" id="/finesse/api/User/1072/[email protected]__104Y2" from="pubsub.finesse1.dcloud.cisco.com">
<event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="/finesse/api/User/1072/Dialogs">
<item id="460c2d27-c914-4c24-a95f-edf9f8df45c21535">
<notification xmlns="http://jabber.org/protocol/pubsub">
<Update>
<data>
<dialogs>
<Dialog>
<associatedDialogUri></associatedDialogUri>
<fromAddress>1071</fromAddress>
<id>18639330</id>
<mediaProperties>
<DNIS>1072</DNIS>
<callType>AGENT_INSIDE</callType>
<dialedNumber>1072</dialedNumber>
<outboundClassification></outboundClassification>
<callvariables>
<CallVariable>
<name>callVariable1</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable2</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable3</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable4</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable5</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable6</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable7</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable8</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable9</name>
<value></value>
</CallVariable>
<CallVariable>
<name>callVariable10</name>
<value></value>
</CallVariable>
</callvariables>
</mediaProperties>
<mediaType>Voice</mediaType>
<participants>
<Participant>
<actions>
<action>ANSWER</action>
</actions>
<mediaAddress>1072</mediaAddress>
<mediaAddressType>AGENT_DEVICE</mediaAddressType>
<startTime>2017-09-15T19:23:36.872Z</startTime>
<state>ALERTING</state>
<stateCause></stateCause>
<stateChangeTime>2017-09-15T19:23:36.872Z</stateChangeTime>
</Participant>
<Participant>
<actions>
<action>UPDATE_CALL_DATA</action>
<action>DROP</action>
</actions>
<mediaAddress>1071</mediaAddress>
<mediaAddressType>AGENT_DEVICE</mediaAddressType>
<startTime>2017-09-15T19:23:36.609Z</startTime>
<state>INITIATED</state>
<stateCause></stateCause>
<stateChangeTime>2017-09-15T19:23:36.819Z</stateChangeTime>
</Participant>
</participants>
<state>ALERTING</state>
<toAddress>1072</toAddress>
<uri>/finesse/api/Dialog/18639330</uri>
</Dialog>
</dialogs>
</data>
<event>POST</event>
<requestId></requestId>
<source>/finesse/api/User/1072/Dialogs</source>
</Update>
</notification>
</item>
</items>
</event>
</message>
那就是 代碼
XElement xmlroots = XElement.Parse(parsingNewXML);
//Dialog = xmlroots.Element("Dialog").Value;
var CallVariable = parsingNewXML.Contains("CallVariable");
var startCall = parsingNewXML.Contains("ALERTING");
if (CallVariable == true && startCall == true)
{
foreach (XElement callID in xmlroots.Descendants("Dialog"))
{
DialogID = callID.Element("id").Value;
//System.Windows.MessageBox.Show(DialogID);
System.Windows.Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() => ((MainWindow)System.Windows.Application.Current.MainWindow).answerCall.Visibility = Visibility.Visible));
}
foreach (XElement callVariables in xmlroots.Descendants("CallVariables"))
{
foreach (XElement callVariable in xmlroots.Descendants("CallVariable"))
{
list = callVariable.Element("value").Value;
}
}
// state = second.Element("state").Value;
}
你的代碼和xml不一致。我不知道你需要什麼。 「如果」條款沒有任何意義。不知道parsingmsg指的是什麼。使用後代而不是祖先要容易得多。 – jdweng
@jdweng 請幫助我我想從這個XML中得到id我該怎麼辦我不知道什麼是代碼來獲取ID我試過這段代碼但沒有幫我 – bavs