Click here to Skip to main content
12,443,996 members (45,215 online)
Click here to Skip to main content
Add your own
alternative version

Stats

73.9K views
947 downloads
29 bookmarked
Posted

Wrapper class for IXMLDDOMDocument

, 10 Apr 2004
Rate this:
Please Sign up or sign in to vote.
A class that provides easy access to XML documents.

Introduction

This simple class provides a few easy methods to work with XML files, including loading XML, building XML hierarchy and saving back to XML file, navigating the nodes and a simple search method.

Classes

CXMLDocument

Methods
HRESULT Load(LPCTSTR fileName); 
HRESULT Save(LPCTSTR fileName);

Loads and saves the XML document.

Members
CXMLNode Root;

The root node of the document.

CXMLNode

Methods
void Find(CXMLNode* rootNode, LPCTSTR nodeName = 
    "*",LPCTSTR nodeText = "*",LPCTSTR attribName = "*",
    LPCTSTR attribValue = "*");
CXMLAttribute* GetAttribute(LPCTSTR attribName);
void AddAttribute(LPCTSTR attribName,LPCTSTR attribValue);
void AddAttribute(LPCTSTR attribName,int attribValue);
void AddAttribute(LPCTSTR attribName,short attribValue);
void AddAttribute(LPCTSTR attribName,double attribValue);
void AddAttribute(LPCTSTR attribName,float attribValue);
void AddAttribute(LPCTSTR attribName,bool attribValue);
void Clear();
CXMLNode* AddNode(LPCTSTR nodeName, LPCTSTR nodeText);
Members
CArray <CXMLNode*,CXMLNode*> Nodes;
CArray <CXMLAttribute*,CXMLAttribute*> Attributes;
CString Name;
CString Text;
Methods usage

CXMLNode* AddNode(LPCTSTR nodeName, LPCTSTR nodeText);

Adds a new node to the array of nodes and returns pointer to this node.

  • nodeName - the new node will be created with this name.
  • nodeText - this will be the text value for the new node.

void AddAttribute(LPCTSTR attribName,LPCTSTR attribValue); + 5 ovverloads.

Adds a new attribute to this node.

  • attribName - the name of the attribute.
  • attribValue - the value of the attribute.

CXMLAttribute* GetAttribute(LPCTSTR attribName);

Finds an attribute by name, returns a pointer to that attribute, NULL if not found.

  • attribName - the name of the attribute to return.

void Clear();

Clears this node of ALL its children, recursively clears the children as well, and clears the attributes also.

void Find(CXMLNode* rootNode, LPCTSTR nodeName = "*",LPCTSTR nodeText = "*",LPCTSTR attribName = "*",LPCTSTR attribValue = "*");

Recursively searches the children of this node, adding any child node that matches the criteria as a child to the supplied root node.

  • rootNode - pointer to the root node that will hold the search results, must not be NULL.
  • nodeName - the name of the nodes to find or "*" for ANY node.
  • nodeName - the text of the nodes to find or "*" for ANY node.
  • attribName - the name of the attribute to find, nodes that have an attribute with this name pass the test, or "*" for ANY.
  • attribValue - the value of the attribute to find, nodes that have an attribute with this value pass the test, or "*" for ANY.

CXMLAttribute

Methods
bool BoolValue();
double DblValue();
int IntValue();

Those methods are value extractors, returns the stored value as bool, double or integer.

Members
CString Name;
CString Value;

Stores the name and the value of the attribute.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Alex Hazanov
Software Developer (Senior) RDV Systems
Israel Israel
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralNew version is available Pin
Alex Hazanov2-Apr-05 23:27
memberAlex Hazanov2-Apr-05 23:27 
GeneralDOM XML Pin
dchauhan27-Mar-05 23:15
memberdchauhan27-Mar-05 23:15 
GeneralRe: DOM XML Pin
Alex Hazanov27-Mar-05 23:29
memberAlex Hazanov27-Mar-05 23:29 
QuestionBug in CXMLNode::Find? Pin
Alex Um18-Mar-05 1:16
memberAlex Um18-Mar-05 1:16 
Questionhow to insert formatting white spaces into output file ? Pin
luk7716-Sep-04 22:17
sussluk7716-Sep-04 22:17 
AnswerRe: how to insert formatting white spaces into output file ? Pin
dutchpower18-Sep-04 2:08
memberdutchpower18-Sep-04 2:08 
GeneralRe: how to insert formatting white spaces into output file ? Pin
luk7718-Sep-04 14:01
memberluk7718-Sep-04 14:01 
GeneralRe: how to insert formatting white spaces into output file ? Pin
Daniel331310-Dec-04 0:35
memberDaniel331310-Dec-04 0:35 
GeneralRe: how to insert formatting white spaces into output file ? Pin
Alex Hazanov10-Dec-04 6:27
memberAlex Hazanov10-Dec-04 6:27 
GeneralCan't seem to use in Visual C++ 5.0 Pin
Hydra_427-Apr-04 1:49
memberHydra_427-Apr-04 1:49 
GeneralRe: Can't seem to use in Visual C++ 5.0 Pin
Alex Hazanov2-May-04 6:19
memberAlex Hazanov2-May-04 6:19 
GeneralWon't compile with PlatForm sdk Pin
bkowald19-Apr-04 11:19
memberbkowald19-Apr-04 11:19 
GeneralRe: Won't compile with PlatForm sdk Pin
Anonymous19-Apr-04 23:28
sussAnonymous19-Apr-04 23:28 
GeneralThanks Alex Pin
Jed215-Apr-04 14:02
memberJed215-Apr-04 14:02 
GeneralNice and clear. Pin
oleg6315-Apr-04 5:17
memberoleg6315-Apr-04 5:17 
GeneralPut your comments directly in the code! Pin
didier_thizy15-Apr-04 1:55
memberdidier_thizy15-Apr-04 1:55 
GeneralRe: Put your comments directly in the code! Pin
Alex Hazanov15-Apr-04 4:11
memberAlex Hazanov15-Apr-04 4:11 
GeneralVery nice... Pin
Antony M Kancidrowski13-Apr-04 23:24
memberAntony M Kancidrowski13-Apr-04 23:24 
GeneralRe: Very nice... Pin
_nico15-Apr-04 15:56
member_nico15-Apr-04 15:56 
GeneralRe: Very nice... Pin
Antony M Kancidrowski17-Apr-04 9:52
memberAntony M Kancidrowski17-Apr-04 9:52 
GeneralRe: Very nice... Pin
Alex Hazanov20-Apr-04 4:05
memberAlex Hazanov20-Apr-04 4:05 
Questionwhat do you want to do with xml? Pin
ChauJohnthan11-Apr-04 2:32
memberChauJohnthan11-Apr-04 2:32 
AnswerRe: what do you want to do with xml? Pin
Anna-Jayne Metcalfe12-Apr-04 23:41
memberAnna-Jayne Metcalfe12-Apr-04 23:41 
AnswerRe: what do you want to do with xml? Pin
Alex Hazanov13-Apr-04 1:16
memberAlex Hazanov13-Apr-04 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160811.3 | Last Updated 11 Apr 2004
Article Copyright 2004 by Alex Hazanov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid