Click here to Skip to main content
Click here to Skip to main content

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

Comments and Discussions

 
GeneralNew version is available PinmemberAlex Hazanov2-Apr-05 23:27 
GeneralDOM XML Pinmemberdchauhan27-Mar-05 23:15 
GeneralRe: DOM XML PinmemberAlex Hazanov27-Mar-05 23:29 
QuestionBug in CXMLNode::Find? PinmemberAlex Um18-Mar-05 1:16 
Questionhow to insert formatting white spaces into output file ? Pinsussluk7716-Sep-04 22:17 
AnswerRe: how to insert formatting white spaces into output file ? Pinmemberdutchpower18-Sep-04 2:08 
GeneralRe: how to insert formatting white spaces into output file ? Pinmemberluk7718-Sep-04 14:01 
GeneralRe: how to insert formatting white spaces into output file ? PinmemberDaniel331310-Dec-04 0:35 
GeneralRe: how to insert formatting white spaces into output file ? PinmemberAlex Hazanov10-Dec-04 6:27 
GeneralCan't seem to use in Visual C++ 5.0 PinmemberHydra_427-Apr-04 1:49 
GeneralRe: Can't seem to use in Visual C++ 5.0 PinmemberAlex Hazanov2-May-04 6:19 
GeneralWon't compile with PlatForm sdk Pinmemberbkowald19-Apr-04 11:19 
GeneralRe: Won't compile with PlatForm sdk PinsussAnonymous19-Apr-04 23:28 
GeneralThanks Alex PinmemberJed215-Apr-04 14:02 
GeneralNice and clear. Pinmemberoleg6315-Apr-04 5:17 
GeneralPut your comments directly in the code! Pinmemberdidier_thizy15-Apr-04 1:55 
GeneralRe: Put your comments directly in the code! PinmemberAlex Hazanov15-Apr-04 4:11 
GeneralVery nice... PinmemberAntony M Kancidrowski13-Apr-04 23:24 
GeneralRe: Very nice... Pinmember_nico15-Apr-04 15:56 
GeneralRe: Very nice... PinmemberAntony M Kancidrowski17-Apr-04 9:52 
GeneralRe: Very nice... PinmemberAlex Hazanov20-Apr-04 4:05 
Questionwhat do you want to do with xml? PinmemberChauJohnthan11-Apr-04 2:32 
AnswerRe: what do you want to do with xml? PinmemberAnna-Jayne Metcalfe12-Apr-04 23:41 
AnswerRe: what do you want to do with xml? PinmemberAlex Hazanov13-Apr-04 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.140814.1 | Last Updated 11 Apr 2004
Article Copyright 2004 by Alex Hazanov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid