Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / XML

XMLLib for PUGXML with XPath

Rate me:
Please Sign up or sign in to vote.
4.33/5 (11 votes)
29 Oct 2009CPOL5 min read 126K   1.2K   38  
A library for PugXML which implements XPath
// PugXMLNode.h: interface for the CPugXMLNode class.
// Copyright (C) 2003, by John Crane
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PUGXMLNODE_H__5CFCBE10_9047_4EA3_A97B_791F66418629__INCLUDED_)
#define AFX_PUGXMLNODE_H__5CFCBE10_9047_4EA3_A97B_791F66418629__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// Include the Pug XML library.

#define _CRT_SECURE_NO_WARNINGS 1

#include "platform.h"
#include "Array.h"
#include "BString.h"

#include "pugxml.h"
#include <sstream>
#include <io.h>
#include <sys\stat.h>

using namespace std;
using namespace pug;
using namespace blue;
using namespace blue::common;

//
// CPugXMLNode class wraps xml_node and provides
// XPATH functionality.
//
class CPugXMLNode : public xml_node
{
public:
	CPugXMLNode();
	CPugXMLNode(xml_node_struct* p);
    CPugXMLNode(const xml_node& r);
	virtual ~CPugXMLNode();

    // Query functions
    Array <xml_node_struct*> FindNodes(const char* srch);
    xml_node_struct* FindNode(const char* srch);
    Array<BString> FindValues(const char* srch);
    BString FindValue(const char* srch);

    // Copies an existing tree under a node
    void AppendTree(xml_node& node);

    // Shorthand for something we will do all the time
    xml_node_struct* append_child_element(LPCTSTR szName)
    {
        xml_node node =  xml_node::append_child(node_element);
        node.name(szName);
        return (xml_node_struct*) node;
    }
protected:
};

class CAddAttributeNodes : public xml_tree_walker
{
public:
    virtual bool for_each(xml_node& node);
};

class CDelAttributeNodes : public xml_tree_walker
{
public:
    virtual bool for_each(xml_node& node);
};

#endif // !defined(AFX_PUGXMLNODE_H__5CFCBE10_9047_4EA3_A97B_791F66418629__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions