XML and JSON are two forms of iOS parsing files, both of which are different.
1>. XML is divided into sax and Dom two ways
Sax reads the file sequentially by line, checks to find content that matches the condition, stops when the DOM is spoken, and reads all of the content into memory to create a tree structure, so the DOM is not suitable for reading large files.
The weakness of the DOM is the advantage of Sax. Sax does not have to add everything to memory, but he reads the file sequentially, so that he cannot read and modify the file arbitrarily, and the DOM tree structure can read and modify the file arbitrarily.
Sax |
Dom |
Read files sequentially (line by row) |
Read the file into memory at once and create a tree-like structure |
The file is read-only once and the file cannot be read arbitrarily |
Arbitrary access to data in the tree structure, with no limit to the number of times |
The file can only be read and cannot be modified |
Files can be modified |
Difficult to develop, write your own event controller |
Easy to develop |
|
|
The differences between SAX and Dom are described in.
Sax is suitable for handling the following issues:
1, to deal with large-scale documents;
2. Only a portion of the folder is needed, or only specific information can be obtained from the file.
3, want to build their own object model when.
The DOM is suitable for handling the following issues:
1, the need to modify the document;
2, need to randomly access the file
2>. JSON is divided into XML and JSON two ways
Xml
The difference between XML and JSON parsing