<?xml version="1.0" encoding="UTF-8"?>
<message xmlns="jabber:client" to="[email protected]/unityXMPP" type="chat" xml:lang="en" from="[email protected]/unityXMPP">
<archived xmlns="urn:xmpp:mam:tmp" id="1503375414608430" by="[email protected]" />
<stanza-id xmlns="urn:xmpp:sid:0" id="1503375414608430" by="[email protected]" />
<body>hi</body>
</message>
我想解析內部XML以獲取id屬性。 我已經創建了任何我發現的命名空間。我能夠從屬性中獲得。以下是c#中的代碼。解析XMPP內部xml
string value = "<message xmlns=\"jabber:client\" to=\"[email protected]/unityXMPP\" type=\"chat\" xml:lang=\"en\" from=\"[email protected]/unityXMPP\"><archived xmlns=\"urn:xmpp:mam:tmp\" id=\"1503375414608430\" by=\"[email protected]\" /><stanza-id xmlns=\"urn:xmpp:sid:0\" id=\"1503375414608430\" by=\"[email protected]\" /><body>hi</body></message>";
XmlDocument xmlDoc = new XmlDocument();
XmlNamespaceManager namespaces = new XmlNamespaceManager (xmlDoc.NameTable);
namespaces.AddNamespace ("ns", "jabber:client");
namespaces.AddNamespace ("ns1", "urn:xmpp:mam:tmp");
xmlDoc.LoadXml (value);
XmlNode messageNode = xmlDoc.SelectSingleNode ("/ns:message", namespaces);
string sender = messageNode.Attributes ["from"].Value;
string receiver = messageNode.Attributes ["to"].Value;
string message = messageNode.InnerText;
XmlNode timeStampNode = xmlDoc.SelectSingleNode ("/ns:message/ns1:archived");
string timestamp = timeStampNode.Attributes ["id"].Value;
那麼,什麼是你的問題? – Programmer
如前所述,我需要解析的內部XML在我現有的代碼,我去取id屬性 –