Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of CMarkup Class operating Xml

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you the content of a sample analysis of CMarkup class manipulation Xml. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Download Markup.cpp and Markup.h

Place these two files in the project directory

3. # include "Markup.h" where CMarkup is needed

Of course, the environment needs to be configured in VC.

Under VC6.0:

a. Add # include "stdafx.h" to the top of the Markup.cpp or

b. Turn off the precompiled header setting for Markup.cpp, as shown below:

Project- > Setting pops up the ProjectSetting dialog box, select Markup.cpp under the file tree on the left, then select "All Configurations" under the "Settings for" drop-down box, and select the C _ Settings for + tab.

Then select the "Precompiled Headers" option under the Category drop-down box, and select "Not Using Precompiled Headers." Just click the button.

Basic use of CMarkup:

For example, to read the contents of the following UserInfos.xml

WangYao 25 Hisin 27

The source code is as follows:

CMarkup xml; bool flag; / / load the Xml file flag = xml.Load ("d:\\ UserInfos.xml"); if (! flag) {AfxMessageBox ("failed to load d:\\ UserInfos.xml, please check"); return;} / / navigate to Root Elem xml.ResetPos (); flag = xml.FindElem ("UserInfos"); / / Root Elem is if (! flag) {return } xml.IntoElem (); / / enter the root node while (xml.FindElem (TEXT ("UserInfo")) {xml.IntoElem (); / / enter / / get name node data flag = xml.FindElem (TEXT ("name")); if (flag) {CString cstrName; cstrName = xml.GetData (); AfxMessageBox (cstrName) } / / get age node data xml.ResetMainPos (); / / ensure that age nodes can be found regardless of the order of name nodes and age nodes flag = xml.FindElem (TEXT ("age")); if (flag) {CString cstrAge; cstrAge = xml.GetData (); AfxMessageBox (cstrAge);} xml.OutOfElem () / / Pop out} xml.OutOfElem (); / / Pop out of the root node

Of course, you don't have to enter the UserInfo node to achieve the same function. The source code is as follows. Please compare it carefully.

Xml.IntoElem (); / / enter the root node while (xml.FindElem (TEXT ("UserInfo")) {/ / get name child node data flag = xml.FindChildElem (TEXT ("name")); if (flag) {CString cstrName; cstrName = xml.GetChildData (); AfxMessageBox (cstrName);} / get age child node data xml.ResetChildPos () / / ensure that the age child node flag = xml.FindChildElem (TEXT ("age")); if (flag) {CString cstrAge; cstrAge = xml.GetChildData (); AfxMessageBox (cstrAge);}} xml.OutOfElem (); / / jump out of the root node regardless of the order of the name child node and the age child node

Tips:

1.IntoElem and OutOfElem methods should be used in pairs

two。 About the function of resetting the Pos of xml

ResetPosResets the current position to the start of the documentResetMainPosResets the current main position to before the first siblingResetChildPosResets the current child position to before the first child

3.SavePos and RestorePos restore xml Pos

SavePosSaves the current position with an optional string name using a hash mapRestorePosGoes to the position saved with SavePos

For example:

... = 'class1' > xml.SavePos (Text ("abc")); OpXml (xml); / / if this function may change the Pos of xml, you can use SavePos and RestorePos to restore the Posxml.RestorePos (Text ("abc")) of xml before the function is executed. Thank you for reading! This is the end of this article on "sample analysis of CMarkup class operation Xml". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report