如何在VC环境下编写程序读取XML文件
如何在VC环境下编写程序读取XML文件?清提供源代码.谢谢.
#import <msxml3.dll> named_guids //导入动态库,装了IE5就有
using namespace MSXML2; //引用命名空间,一般可以把命名空间理解成类和接口的集合,呵呵,对不对我也不知道了
#include <vector>
using namespace std;
struct FIELD
{
public:
CString name;
CString type;
CString length;
CString explain;
CString allowNull;
CString autoIncrease;
};
class Xml
{
public:
Xml(void);
~Xml(void);
private:
HRESULT hr;
MSXML2::IXMLDOMDocumentPtr pDoc; //XML文档接口指针
public:
void AddKey(CString moduleName,CString keyName, CString keyValue);
CString ReadKeyValue(CString moduleName, CString keyName);
private:
void NewDocument(CString moduleName, CString keyName, CString keyValue);
public:
bool ReadTable(CTreeCtrl * tree);
bool ReadFields(CString tableName,vector<FIELD> &fields);
bool SaveTable(vector<FIELD> fields,CString tableName,bool bNew);
};
//-------------------------------------------------------------------------------------------------------------------------------------
上面是头文件,这是cpp文件
#include "StdAfx.h"
#include "xml.h"
Xml::Xml(void)
{
CoInitialize(NULL); //初始化COM
hr=CoCreateInstance(MSXML2::CLSID_DOMDocument,NULL,CLSCTX_ALL,MSXML2::IID_IXMLDOMDocument,(void**)&pDoc); //创建XML文档实例
}
Xml::~Xml(void)
{
CoUninitialize();
}
void Xml::AddKey(CString moduleName,CString keyName, CString keyValue)
{
CString selectString="AppSetting/"+moduleName; //XML节点定位字符串,定位到节点名为
相关文档:
XPath 语法
2007-06-05 17:24
XPath 语法
作者:w3pop.com 翻译/整理:w3pop.com 发布:2007-04-29 浏览:674 :: ::
XPath Nodes(节点) XPath Axes
XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.
XPath 通过路径表达式从XM ......
public static IList<News> GetAllNews()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("你读取的地址:例如 ......
Perl的XML::DOM功能很强大,利用它可以轻易地分析XML文档,也可以建立XML文档。
常用的类包括:
XML::DOM::Node:所有类的基类,表示一个XML节点。
XML::DOM::Parser:XML解析器,将XML字符串解析成XML::DOM::Document对象。
XML::DOM::Document:指向XML文档的根节点。
XML::DOM::Element:指向一个元素,通常由XML:: ......
创建XML文件:
public boolean createXML(){
try{
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("root");
Element personNode = root.addElement("person");
Element sonNode = personNode ......