易截截图软件、单文件、免安装、纯绿色、仅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面试题汇总

1、  int a=2,b=11,c=a+b++/a++; 则c值为多少?
【考点】编码规范。
表面上考察你对运算符优先级的掌握程度,但实际上优先级这些玩意很难死记硬背得住?大家的疑惑不就是运算符的结合顺序么?那么如何去避免呢?c=a+((b++)/(a++))不就行了么,其实问题背后考察的是你的编码规范,如何写清晰易懂的代码,如何在一个团 ......

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 ......

linux内核移植s3c2410,准备工作

1.首先是获得linux内核源码,好像是废话,下载地址如下:ftp://ftp.kernel.org/pub/linux/kernel/v2.6/下载:
linux-2.6.16.22.tar.bz2  patch-2.6.22.6.bz2
上面一步需要说明的是一般而言,linux内核的各个补丁文件是根据某个linux内核的版本号来作的patch。
将上面的两个压缩文件解压:
tar jxvf linux-2.6.22.ta ......

C#中C/C++程序员注意问题

1、C/C++程序员请注意,不能在case语句不为空时“向下执行”。
  2、值类型和引用类型之间的区别:C#的基本类型(int,char等)都是值类型,是在栈中创建的。而对象是引用类型,创建于堆中,需要使用关键字new。
  3、在C#中通过实例访问静态方法或成员变量是不合法的,会生成编译器错误。但是我们可以通过声 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号