VC parsing xml--Parsing XML using CMarkup class

Source: Internet
Author: User

The VC parsing xml--uses the CMarkup class to parse the XML. --yxifu

(a) First to talk about the characters in the XML, manually fill in the note.

Character entity
& & or & #38; #38;
' ' or & #39;
> > or & #62;
< &lt; or & #38;& #60;
"&quot; or & #34;

(ii) The source code of the CMarkup class.

This is currently the latest version;

This is the official website sample file, take out the inside of Markup.cpp and Markup.h, import your project inside, CMarkup class can use;

Download Address: Http://www.firstobject.com/Markup90.zip October 1, 2007 the latest version of the official website

If you can't download it, you can go to the official website to download http://www.firstobject.com/dn_markup.htm

(iii) Create an XML document.

CMarkup XML;
Xml. Addelem ("ORDER");
Xml. Addchildelem ("ITEM");
Xml. Intoelem ();
Xml. Addchildelem ("SN", "132487a-j");
Xml. Addchildelem ("NAME", "Crank casing");
Xml. Addchildelem ("QTY", "1");
Xml. Save ("C://userinfo.xml");

The effect is as follows:

CMarkup XML;
 (XML. Findchildelem ("ITEM"))
{  XML.    Intoelem ();  XML.    Findchildelem ("SN");  CString cssn = XML.    Getchilddata ();  XML.     Findchildelem ("QTY");
Nqty = Atoi (XML.    Getchilddata ());  XML. Outofelem ();
}
Add in the last face, use Addelem; add at the top, use Insertelem.
CMarkup XML;
Xml. Load ("C://.xml");
Xml. Addelem ("ORDER");
Xml. Intoelem (); 



XML.    Addelem ("ITEM"); XML.    Intoelem (); XML. Addelem ("SN", "4238764-a" ); add element XML. Addelem ("NAME", "bearing" );//add element XML. Addelem ("QTY", " " ");//Add Element
Xml. Addelem ("SHIPMENT");
Xml. Intoelem (); 
Xml. Addelem ("POC");//add Element
XML. Setattrib ("type", "non-emergency");//Add attribute
XML. Intoelem (); 
Xml. Addelem ("NAME", "John Smith");//add Element
XML. Addelem ("TEL", "555-1234");//add Element
XML. Save ("C://.xml");

The effect is as follows:

(vi) Modifying elements and attributes

If the attribute type in the POC is changed to: change;

Element Tel changed to: 123456789

CMarkup XML;
if (XML. Load ("Userinfo.xml"))
{
CString strUserID = _t ("");
Xml. Resetmainpos ();
if (XML. Findchildelem ("SHIPMENT"))
{
Xml. Intoelem ();
if (XML. Findchildelem ("POC"))
{
Xml. Intoelem ();
CString Str_type=xml. Getattrib ("type");
MessageBox (Str_type);
Xml. Setattrib ("type", "change");
strUserID = XML. GetData ();

if (XML. Findchildelem ("TEL"))
{
Xml. Intoelem ();
Xml. SetData ("123456789");
Xml. Save ("Userinfo.xml");
Return
}
}
}
}

(vii) Delete elements:

Delete the Sn=132487a-j item.

CMarkup XML;
if (XML. Load ("Userinfo.xml"))
{
CString strUserID = _t ("");
Xml. Resetmainpos ();
if (XML. Findchildelem ("ITEM"))
{
Xml. Intoelem ();
CString STR_SN;
Xml. Findchildelem ("SN");
Str_sn=xml. Getchilddata ();
if (str_sn== "132487a-j")
{
Xml. Removeelem ();
Xml. Save ("Userinfo.xml");
}
}
}

Transferred from: http://hi.baidu.com/yxifu/blog/item/fa1569225bda52a44623e8f0.html

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.