TinyXml is parsed from memory and Saved to memory

Source: Internet
Author: User

There are many examples of TinyXml on the Internet. I also need to parse XML recently. I searched for it online and found that TinyXml is the most suitable.

TinyXml supports both Windows and Linux platforms, and is small and comprehensive, including operations on Various XML features.

However, in the United States, although there are many online application instances, most of them parse and save data to files. What I need is to parse the data in the memory and save the data to the memory.

TinyXml online help documentation URL: http://www.grinninglizard.com/tinyxml2docs/index.html

First of all, TinyXml regards the labels, attributes, declarations, comments, and values in Xml data as "nodes", which are embodied in the TiXmlNode data structure.

Because of the restrictions on the conditions, we cannot use test cases now. Let's write down the usage and hope to help you.

Load data from memory:

const char *cszXml = "<?xml version="1.0"?><BOOK><BOOKNAME>XML</BOOKNAME></BOOK>";TiXmlDocument doc;doc.Parse(cszXml);if (true == doc.Error()){cout << "Parse XML data error: " << doc.ErrorDesc() << endl;return;}

Save data to memory:

TinyXml can save data to a file or print data to the screen. Of course, it can also be saved directly to the memory, which is actually the printing function of the application.

Extern TiXmlDocument doc ;//! XML document extern char szXml []; //! Storage result string TiXmlPrinter printer; printer. VisitEnter (doc); // printer. SetIndent ("");//! Set the identifier starting with each line. The default value is 4 spaces // printer. SetLineBreak ("");//! Set the row delimiter. The default value is "\ r \ n "//! The preceding two rows can be used to replace printer. SetStreamPrinting ();//! Set the start identifier to "" and the line separator to "" sprintf (szXml, printer. CStr ());//! Save the result to szXml, a C-style string //! Int nSize = printer. Size ();//! String Length

By the way, the following sentence is provided:

Determine whether a tag has a sub-Tag:

Extern TiXmlElement xmlElem; if (xmlElem. FistChildElement () {// TODO: Sub tag} else {// TODO: No sub tag}

Game over!

It is easy to write, but I hope it will be useful to everyone.

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.