Description
The original version of the cxmlparse class is from codeproject.com.
Http://download.csdn.net/source/534628
During years of use, I made some upgrades,
Including:
1. modified some original author bugs.
2. Added support for Chinese Parsing
3. Remove the dependency on MFC and change it to stl c ++.
Common interface functions
1. bool load (const char * szfilename); load XML document content from XML file
2. bool save (const char * szfilename); Archive
3. addelem add nodes
4. addchildelem Add a subnode
5. Add node attributes to addattrib
6. addchildattrib adds subnode attributes
7. intoelem enters the subnode
8. outofelem jumps out of the subnode
Example
1. document loading and saving
Cxmlparse XML;
XML. Load ("C: // demo. xml ");
XML. Save ("C: // export. xml ");
2. Create an XML document
Cxmlparse XML;
XML. addelem ("Demo ");
XML. addchildelem ("child ");
XML. addchildattrib ("name", "nieo ");
XML. addchildattrib ("sex", 1 );
The XML content is
<Demo> <child name = "nieo" Sex = "1"/> </demo>
3. Create multi-layer XML documents
Cxmlparse XML;
XML. addelem ("Demo ");
XML. addchildelem ("root ");
XML. cancelem ();
XML. addchildelem ("child ");
XML. addchildattrib ("name", "nieo ");
XML. addchildelem ("child ");
XML. addchildattrib ("name", "Simen ")
XML. outofelem ();
The XML content is
<Demo> <root> <child name = "nieo"/> <child name = "Simen"/> </root> </demo>
4. XML document parsing take the following document as an Example
<HTML>
<Header> <meta name = "author" content = "csdn"/>
<Body> <nieo sex = "1" nickname = "nieoding"/> </body>
Find nieo's nickname.
Cxmlparse XML;
XML. Load (.....);
XML. findchildelem ("body ");
XML. cancelem ();
If (XML. findchildelem ("nieo "))
{
String nickname = xml. getchildattrib ("nickname ")
}
5. Interaction between STD: string and cxmlparse
Cxmlparse-> STD: String
Cxmlparse XML;
.........
STD: String Doc = xml. getdoc ();
STD: String-> cxmlparse
STD: String Doc = "<body>... </body> ";
Cxmlparse XML (Doc. c_str ());