First, using the extended file in XMPP for XML data parsing, the framework of XML data parsing needs to be written manually.
Contains this header file nsxmlelement+xmpp.m. The following methods are used primarily in this file:
-(Nsxmlelement *) Elementforname: (NSString *) Name{nsarray *elements = [self elementsforname:name];if ([elements Count] & Gt 0) {return [elements objectatindex:0];} else{//there is a bug in the Nsxmlelement elementsforname:method.//consider the following XML fragment:////<query xmlns= "Jabber:iq:private" >// <x xmlns= "Some:other:namespace" ></x>//</query>////Calling [Query elementsforname:@ "x"] results in an empty array!////However, it'll work properly if you use the following://[q Uery elementsforlocalname:@ "x" uri:@ "Some:other:namespace"]////The trouble with this is so we may not always know the xmlns in advance,//-in-particular case there is no-to-access the element without looping through. This bug is submitted to Apple on June 1st, and is classified as "serious".//--!! --this bug does not exist in Ddxml--!! --return Nil;}}
The XML data parsing framework is written differently for different XML data nodes, and can be drawn out as a more versatile method.
-(Nsarray *) emailaddresses { //Get email node nsxmlelement *emailele = [self elementforname:@ "email"]; Get the sub-node of email// Nsarray *children = [Emailele children];// Wclog (@ "%@", children); Nsxmlelement *useridele = [Emailele elementforname:@ "USERID"]; Get mailbox nsstring *email = [Useridele stringvalue]; Wclog (@ "%@", email); #warning only the UserID's mailbox if (Email.length > 0) { return @[email]; } return nil;}
External use
Get mailbox Nsarray *emails = myvcard.emailaddresses; if (Emails.count > 0) { self.emailLabel.text = emails[0];; }
Second, using the extension file in XMPP to add, delete and change XML data, the framework of XML data should be written manually.
Contains this header file nsxmlelement+xmpp.m. The main use of this file is the following method to delete the node:
/** * This method removes the first child element for the given name. * If No child elements exist for the given name, this method does nothing.**/-(void) Removeelementforname: (NSString *) name { Nsxmlelement *element = [self elementforname:name]; if (Element) { [self removechildatindex:[[self Children] indexofobject:element]; }}
Third-party XML parsing kissxml[parsing XML]
Contains this header file DDXMLNODE.M. The main use of this file is to set up a new node in the following way:
+ (ID) elementwithname: (NSString *) name StringValue: (NSString *) String{return [[Ddxmlelement alloc] Initwithname:name Stringvalue:string];}
The XML data parsing framework is written differently for different XML data nodes, and can be drawn out as a more versatile method.
-(void) Setemailaddresses: (Nsarray *) Emails { //mailbox array can only have one mailbox nsassert (Emails.count = = 1,@ "Mailbox array can have only one mailbox"); / * * <EMAIL>
External use, assign value to the mailbox, then the operation is to update to the server.Resolve Mailbox //myvcard.mailer = Self.emailLabel.text; if (Self.emailLabel.text.length > 0) { //save only one mailbox myvcard.emailaddresses = @[self.emaillabel.text]; }
iOS development: XML data parsing and modification uploads under XMPP