XML data exchange format in iOS, iosxml

Source: Internet
Author: User
Tags xml parser xsl

XML data exchange format in iOS, iosxml

XML is a self-describing data exchange format, but the XML data exchange format is not lightweight in JSON, but it is undeniable that XML is widely used, for example, in ROS (an open-source robot operating system), XML is used to describe the dependency of packages.

XML document operations include "read" and "write". The process of reading and analyzing XML documents is called "Parsing" XML documents, parsing XML documents accounts for a large proportion in actual development.

Currently, there are two popular methods for reading and writing XML documents: SAX and DOM. SAM is an event-driven parsing mode. When parsing XML, the program reads the XML document from top to bottom. If the start tag, end tag, and attribute are encountered, the corresponding event is triggered, however, the disadvantage of parsing XML files is that they can only read XML documents, but cannot be written into XML documents. But it also has the advantage that the resolution speed is fast, and the SAX resolution mode is recommended in iOS.

The DOM mode analyzes an XML document as a tree structure to obtain the content of a node, related attributes, or add, delete, or modify the content of a node. After the XML Parser loads the XML file, the DOM considers the elements of the XML file as a node in a tree structure and reads them into the memory at one time. If the document is large, the resolution speed will be slow, which is inevitable. However, the DOM mode cannot be replaced by SAX, that is, DOM can modify XML documents.

NSXML

NSXML is Apple's default parsing framework, which uses the SAX mode for parsing. It is a representative of the SAX parsing mode. The core of the NSXML framework is NSXMLParser and its delegation protocol NSXMLParserDelegate. The main parsing work is completed in the implementation class of the delegate protocol. Many callback methods are defined in the delegate, and the SAX Parser traverses the XML document from top to bottom, related methods are triggered when the start tag, end tag, document start, document end, and string are encountered.

Common Methods:

(1) parserDidStartDocument -- triggered at the beginning of the document

(2) parser: didStartElement: namespaceURI: qualifiedName: attributes -- triggered when a start tag is encountered. The namespaceURI part is the namespace, The qualifiedName is the qualified name, and the attributes is the attribute set of the dictionary

(3) parser: foundCharacters -- triggered when a string is encountered

(4) parser: didEndElement: namespaceURI: qualifiedName -- triggered when an end tag is encountered

(5) parserDidEndDocument -- triggered when the document ends

The following is a parsed XMLParser class.

XMLParser. h

# Import <Foundation/Foundation. h> @ interface XMLParser: NSObject <NSXMLParserDelegate> // start (void) start; @ end
XMLParser. m

-(Void) start {NSString * path = [[NSBundle mainBundle] pathForResource: @ "Test" ofType: @ "xml"]; // parse a Test. NSURL * url = [NSURL fileURLWithPath: path]; // start parsing xml NSXMLParser * parser = [[NSXMLParser alloc] initWithContentsOfURL: url]; parser. delegate = self; [parser parse]; NSLog (@ "Resolution completed... ");}

If there are any deficiencies, I hope to point out!



What is the internationally standardized data exchange format XML?

XML is the abbreviation of eXtensible Markup Language. XML is a simple data storage language that uses a series of simple tags to describe data. These tags can be conveniently created, although XML occupies more space than binary data, XML is extremely easy to master and use.

Different from databases such as Access, Oracle, and SQL Server, XML provides powerful data storage and analysis capabilities, such as data indexing, sorting, searching, and consistency, XML only displays data. In fact, the biggest difference between XML and other data forms is that it is extremely simple. This is an advantage that looks a little refined, but it makes XML different.

The simplicity of XML makes it easy to read and write data in any application, which makes XML quickly the only public language for data exchange. Although different application software also supports other data exchange formats, but soon they will support XML, which means that the program can be more easily combined with information generated on Windows, Mac OS, Linux, and other platforms, then it is easy to load XML data into the program, analyze it, and output the results in XML format.

The predecessor of XML is SGML (The Standard Generalized Markup Language), which was developed by IBM since 1960s)

Like HTML, XML (Extensible Markup Language) is a subset of the General Markup Language Standard (SGML). It is the standard used to describe the data content and structure on the network. Even so, XML is not like HTML. HTML only provides a general method for displaying information on pages (without context-related and dynamic functions), and XML gives context-related functions to Data, it inherits most of SGML functions, but uses less complex technologies ..

To make SGML more user-friendly, XML redefined some of sgml's internal values and parameters, removing a large number of rarely used functions. These complex features complicate SGML when designing websites. XML retains the structured functions of SGML, so that website designers can define their own document types. XML also introduces a new document type, so that developers do not need to define document types.

Because XML is developed by W3C, XML standardization is undertaken by W3C XML working groups composed of experts from various places and industries, they emailed their opinions on the XML standard and put forward their opinions (www.w3.org/TR/WD-xml ). Because XML is a public format (it does not belong to any company), you don't have to worry that XML technology will become a profitable tool for a few companies. XML is not a language that is attached to a specific browser.

XML (Extensible Markup Language) is derived from an older language called SGML (Standard Generic Markup Language. The main purpose of SGML is to define the syntax that uses tags to represent the markup language of data.

A tag consists of text enclosed by a smaller sign (<) and a greater sign (>), for example, <tag>. The start tag indicates the start of a specific region, for example, <start>; the end tag defines the end of a region, except for a slash (/) followed by a smaller sign, it is basically the same as the starting label, for example, </end>. SGML also defines the attributes of tags, which are the values defined between minor signs and greater than signs, such as the src feature in . If you think it looks familiar, you should know... the full text>
 
Xml advantages

Lightweight data storage files
1) the content and structure of XML documents are completely separated.
This feature brings great benefits to XML applications. Based on these features, enterprise systems can easily achieve the complete separation of content management and process management. For example, a system architect can focus only on the interface definitions in various stages of process operation, each department can focus on content release and maintenance.
For example, Microsoft's product Biztalk uses the characteristics of XML content and structure separation to separate content and process definitions. Another widely used technology is XSL. Because of the separation of content and structure of XML files, XSL can change the structure of XML files without affecting the content.
2) High interoperability
Most plain text file formats have this advantage. Text files can be easily transmitted through the firewall to communicate with different systems on different operating systems. XML, as a plain text file format, also has this advantage.
3) Standardized
XML has a unified standard syntax. All XML documents supported by any system and product have a unified format and syntax. In this way, XML has the cross-platform and cross-system features. As a comparison, as a text language, JavaScript standards are far less unified than XML, so that the same static page often produces different results in different browsers, script programmers often need to judge the script version supported by the client at the entrance of the program.
4) supports multiple encodings
Compared with common text documents, XML documents themselves contain the encoding records used, which facilitates the processing of data by multilingual systems.
5) scalability
XML is an extensible language. You can further limit the scope of use and document format based on the basic syntax of XML to define a new language. For example, MathML (Mathematical Markup Language), CRF (Chemical Markup Language), and teaml (Technical Data Markup Language), each language is used in its specific environment.

XML
1. Data Exchange
It is no longer a secret to use XML for data exchange between applications and companies. It should undoubtedly be put first. So why is XML so important in this field? The reason is that XML uses elements and attributes to describe data. During data transmission, XML always retains data structures such as parent/child relationships. Several applications can share and parse the same XML file without having to use the traditional String Parsing or disassembling process.
On the contrary, normal files do not describe each data segment (except in the header file), and do not retain the data link structure. Using XML for data exchange can make applications more flexible, because XML data can be accessed by location (the same as normal files) or element name (from the database.

2. Web Services
Web services are one of the most exciting revolutions that allow people using different systems and programming languages to communicate with each other and share data. The Foundation is that the Web server uses XML to exchange data between systems. Exchange data can be standardized by common XML tags, for example, on the Simple Object Access Protocol (SOAP) platform.
SOAP can transmit messages between objects constructed in different programming languages. This means that a C # object can communicate with a Java object. This communication can even happen between objects running on different operating systems. DCOM, CORBA, or Java RMI can only transmit messages between tightly coupled objects, while SOAP can transmit messages between loosely coupled objects.

3. Content Management
XML uses only elements and attributes to describe data, rather than data display methods. In this way, XML provides an excellent way to mark content independent of the platform and language.
Using languages like XSLT, you can easily convert XML files into various formats, such as HTML, WML, PDF, flat file, EDI, and so on. XML has the ability to run on different system platforms and convert to different formats of target files, making it an excellent choice in the content management application system.

4. Web Integration
More and more devices now support XML. This allows Web developers to use XML to transmit data between personal e-assistants and browsers ....... Remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.