易截截图软件、单文件、免安装、纯绿色、仅160KB

用c读取XML文件

 
  可以将XML文件的树(只有一个顶层节点).于是理所当然的可以用树作为XML的一种存储结构.
我将在这里用C++实现对简单的XML文件的解析.
1.选择存储结构:
树型数据结构有多种存储方式,我将用"孩子兄弟表示法",定义如下:
typedef struct CSNode
{
int subNodes;
string data;
string name;
struct CSNode *firstChild,*nextsibling,*parent;
CSNode* operator=(CSNode cnode)
{
this->data = cnode.data;
this->firstChild = cnode.firstChild;
this->name = cnode.name;
this->nextsibling = cnode.nextsibling;
this->subNodes = cnode.subNodes;
return this;
}
}CSNode,*CSTree;
2.定义一个ADT,提供操作的公共接口.取名为 xml
class xml
{
public:
xml();
xml(char *fileName);
~xml();
CSNode& CreateTree(); // 建立存储结构
bool findData(const char *nodepos); // 查找节点值
bool findData(const char *partent, const char *child,string *data); // 查找节点值
bool readfile_(); // 读取xml源文件
void allocate(); // 释放节点资源
private:
string _fileCope;
char* _filename;
CSNode *head;
};
3.具体实现
#include "stdafx.h"
#include "xmlCreate.h"
#include "wstack.h"
#include <algorithm>
using namespace std;
xml::xml()
{
}
xml::xml(char *fileName) : _filename(fileName)
{
head = new CSNode;
}
xml::~xml()
{
delete head;
}
CSNode& xml::CreateTree()
{
CSNode *p = new CSNode;
CSNode *q = new CSNode;
CSNode *s = new CSNode;
wstack<string> nameStack;
wstack<CSNode> nodeStack;
string tmpstr;
string name,tempname,rootName,headName;
int noods = 0;
bool subroot = true,next = false,poproot = false;
unsigned short int enoods = 0;
char ps;
for (size_t i = 0; i < _fileCope.size(); ++i){
ps = _fileCope[i];
if (_fileCope[i] == ' ' || _fileCope[i] == '' || _fileCope[i] == '\t' || _fileCope[i] == 0x09 || _fileCope[i] == 0x0d)continue;
if (_fileCope[i] == '<' && _fileCope[i+1] != '/') {
s = new CSNode;
s->subNodes = 0;
enoods = 0;
}
else if (_fileCope[i] == '>') {
enoods = 0;
s->name = tmpstr;
nameStack.push(


相关文档:

Java中无法捕获C程序printf输出的问题

在测试
ConsoleRunner
的过程中发现一个有意思的现象,一段很简单的
C
程序:
 
#include <stdio.h>
#include <windows.h>
 
int main() {
   
int i = 0;
   
for (;;) {
       
printf("%d\n", i++); ......

c文件操作 (转)

文件
文件的基本概念
  所谓“文件”是指一组相关数据的有序集合。 这个数据集有一个名称,叫做文件名。 实际上在前面的各章中我们已经多次使用了文件,例如源程序文件、目标文件、可执行文件、库文件 (头文件)等。文件通常是驻留在外部介质(如磁盘等)上的, 在使用时才调入内存中来。从 ......

c/c++到底能做什么?

    这两天学习C++学累了,看了很多的网站论坛,突然感觉迷茫了,c/c++到底能做什么呢?现在JAVA很热,也很好找工作,而且学起来还听说很容易入门。不用学计算机基础类的知识,可C/C++就不同了,只学编程还不行,还得学什么数据结构,算法,计算机原理,操作系统,汇编语言,编程用具等等,需要好多,感觉一 ......

UVa 327 Evaluating Simple C Expressions

/*
coder: ACboy
date: 2010-3-14
result: 1A
description: UVa 327 Evaluating Simple C Expressions
*/
#include <iostream>
#include <algorithm>
using namespace std;
struct Node {
char name;
int value;
int lastValue;
int pos;
};
int cmp(const Node & a, const Node &a ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号