send request (URL)
1. Client----------------"service side
Send data (Json/xml)
<---------------------------
1. xml Format
Common: plist file, NetEase news, Sina News
XML document
Tag/node <root></root> outermost root is called root node
Tag name Root
<CityName> Beijing </CityName>
Tag Value/node value Beijing
<item key= "1" value= "newspaper" > </Item>
key= "1" attribute node
Property: key= "1"
Property Name: Key
Property value: "1"
*xml data (document) top-down tree structure
*<root>.....</root> (a complete node), the name of the root node (the title) in the middle (...) For the content of the node
* Each XML document has only one root node (the outermost node in the tree structure)
*xml documents (data) are made up of multiple nodes (the child nodes, child nodes, such as the root node ...).
*/
Two-fork Tree
JSON
JSON (JavaScript Object Notation) is a lightweight data interchange format with good readability and easy-to-write features. Data exchange between different platforms is possible. JSON uses a very high compatibility, completely independent of the language text format, but also has a similar to the C language habits (including C, C + +, C #, Java, JavaScript, Perl, Python, etc.) the behavior of the system. These features make JSON an ideal data exchange language.
XML
The Extensible Markup Language (extensible Markup Language, XML), which is used to tag electronic files with a structured markup language that can be used to tag data, define data types, is a source language that allows users to define their own markup language. XML uses a DTD (document type definition) to organize data into a single, unified format, cross-platform and language, and has long been recognized as a standard in the industry.
JSON (data relative to XML, lightweight, high transfer rate, less redundant data.) Cons: Poor readability)
XML (more redundant data, advantages: Strong readability, strong extensibility)
The/*xml Extensible Markup Language, which is used primarily for client-to-server data interaction.
*xml Data features: A top-down tree structure with only one root node:<root>...</root>
* The process of parsing XML data is the process of acquiring node content
*xml and json:xml data are readable and extensible, but data with no JSON format is lightweight and redundant data is more
*/
Nsjsons .....
Sbjson
1. System Nsxmlparser more complex
2. Third party open Source Library GData common or Kissxml
Parsing XML frequently used libraries: GData
The bottom layer uses the LIBXML2 Library of the system, adding LIBXML2 when used
(1) Import Gdata Library and drag it directly in
(2) Set header file search path
Build Setting--->header search Path
Add/USR/INCLUDE/LIBXML2
(3) Add libxml Binary Library
Build Phases---> Link Binary
Add Libxml2.dylib
(4) If it is an arc project
Build Phases---> Compile Source File
GDATAXMLNODE.M (non-ARC)
GData third-party libraries have two ways of parsing
1. Get root node all elements traverse all child nodes
2.xpath Syntax
2. XPath gets the specified node
@ "http://10.0.8.8/sns/my/user_list.php?format=xml&page=1&number=10" to get the data in XML format
Sina News
Http://rss.sina.com.cn/sina_all_opml.xml
The function of mastering
Gdataxmlnode
Gets the value of the current node
-(NSString *) stringvalue;
Gets the number of node nodes in the current section
-(Nsuinteger) ChildCount;
Get an array of child nodes
-(Nsarray *) children;
Get child nodes by index
-(Gdataxmlnode *) Childatindex: (unsigned) index;
Gdataxmlelement
Get all node arrays with node name named name based on node name
-(Nsarray *) Elementsforname: (NSString *) name;
Get the properties of a node
-(Nsarray *) attributes;
Get attribute nodes by property name
-(Gdataxmlnode *) Attributeforname: (NSString *) name;
Gdataxmldocument
Create a document tree
-(ID) Initwithdata: (NSData *) data encoding: (nsstringencoding) Encoding error: (NSERROR *) error;
Get and Node
-(Gdataxmlelement *) rootelement;
Gets the specified array of nodes according to the XPath syntax
-(Nsarray *) Nodesforxpath: (NSString *) XPath error: (NSERROR * *) error;
Functions added by extended functions on Gdata
Add by Lzx 2014-05-28
We can extend a few new ways to this open source library.
Then just import the current file's source code so you can directly use the
Gets the text information (value) of the child node of the current node with the specified name, name (only a child node called name)
-(NSString *) Stringvaluebyname: (nsstring*) subname;
Gets the text information (value) of the child node of the current node with the specified name, name, if there are multiple child nodes with the same name
-(Nsarray *) Stringvaluesbyname: (nsstring*) subname;
Gets the value of the specified name of the current node Attrname property
-(nsstring*) Attributevaluebyname: (nsstring*) Attrname;
Gets the value of all child nodes (the names of all child nodes to be obtained in the array) for the current node specified name
-(Nsdictionary *) Subdictwitharray: (nsarray*) subnames;
JSON and XML