簡體   English   中英

創建用於xml響應的nsxmlobject iOS,

[英]Create nsxmlobject iOS for xml response,

我正在聊天應用程序上,在某個地方我需要創建具有所需xml結構的nsxmlobject。

我用於簡單xml的ios代碼。

 NSString* server = @"conference.server.local"; //or whatever the server address for muc is
XMPPJID *servrJID = [XMPPJID jidWithString:server];
XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:servrJID];
[iq addAttributeWithName:@"from" stringValue:[xmppStream myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[xmppStream sendElement:iq];

上面的代碼用於創建以下xml格式。

<iq from='hag66@shakespeare.lit/pda'
id='yh2fs843'
to='wiccarocks@shakespeare.lit/laptop'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

誰能幫我創建NSXMLElement,它為我提供了以下類型的xml表示形式。

 <iq from='juliet@capulet.lit/balcony' type='set' id='pip1'>
 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
 <publish node='storage:bookmarks'>
  <item id='current'>
    <storage xmlns='storage:bookmarks'>
      <conference name='The Play&apos;s the Thing' 
                  autojoin='true'
                  jid='theplay@conference.shakespeare.lit'>
        <nick>JC</nick>
      </conference>
    </storage>
  </item>
</publish>
<publish-options>
  <x xmlns='jabber:x:data' type='submit'>
    <field var='FORM_TYPE' type='hidden'>
      <value>http://jabber.org/protocol/pubsub#publish-options</value>
    </field>
    <field var='pubsub#persist_items'>
      <value>true</value>
    </field>
    <field var='pubsub#access_model'>
      <value>whitelist</value>
    </field>
  </x>
</publish-options>
</pubsub>
</iq>

您可以這樣:

     NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
        [iq addAttributeWithName:@"type" stringValue:@"set"];
        [iq addAttributeWithName:@"id" stringValue:@"pip1"];

        [iq addChild:[NSXMLElement elementWithName:@"pubsub" xmlns:@"http://jabber.org/protocol/pubsub"]];

        NSXMLElement *publish = [NSXMLElement elementWithName:@"publish"];
        [publish addAttributeWithName:@"node" stringValue:@"storage:bookmarks"];
        NSXMLElement *item = [NSXMLElement elementWithName:@"item"];
        [item addAttributeWithName:@"id" stringValue:@"current"];
        [publish addChild:item];
        [publish addChild:[NSXMLElement elementWithName:@"storage" xmlns:@"storage:bookmarks"]];
        NSXMLElement *conference = [NSXMLElement elementWithName:@"conference"];

        [iq addChild:publish];
        --
        --
        --;

它還沒有完成,但是我希望您對如何做有一個了解。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM