= "";
}
else{
subroot = true;
next = false;
}
if (tname == rootName) {
p->nextsibling = NULL;
p->firstChild = NULL;
p = q;
poproot = true;
}
else if (tname == headName) {
q->nextsibling = NULL;
}
}
else
{
enoods = 0;
if (_fileCope[i] != ''/'')tmpstr += _fileCope[i];
}
}
delete s;
return *head;
}
bool xml::readfile_()
{
ifstream infile(_filename,ios::binary);
if (!infile) {
//AfxMessageBox("Openfile failed!");
return false;
}
bool lable = false;
string _tfc(""),_lable("");
char c;
while(infile.get(c))_tfc += c;
for (size_t i = 0; i < _tfc.size(); ++i){
if (_tfc[i] == '' '' || _tfc[i] == ''\n'' || _tfc[i] == ''\t'' || _tfc[i] == 0x09 || _tfc[i] == 0x0d)continue;
if (_tfc[i] == ''<'' && _tfc[i+1] == ''?'') {
lable = true;
}
else if (_tfc[i] == ''?'' && _tfc[i+1] == ''>'') {
lable = false;
_lable += _tfc[i];
_lable += _tfc[i+1];
i += 2;
continue;
}
else if (_tfc[i] == ''<'' && _tfc[i+1] == ''!'' && _tfc[i+2] == ''-'') {
lable = true;
}
else if (_tfc[i] == ''-'' && _tfc[i+1] == ''-'' && _tfc[i+2] == ''>''){
lable = false;
_lable += _tfc[i];
_lable += _tfc[i+1];
_lable += _tfc[i+2];
i += 3;
}
if (lable) _lable += _tfc[i];
else _fileCope += _tfc[i];
}
return true;
}
bool xml::findData(const char *nodeName)
{
CSNode *p = head;
string _nodeName = nodeName;
return true;
}
bool xml::findData(const char *parent, const char *child,string *data)
{
CSNode *p = head->firstChild;
string _parent(""),_child("");
bool isfound = false;
while (p != NULL) {
if (p->name == parent) {
p = p->firstChild;
while (p != NULL) {
if (p->name == child) {
*data = p->data;
return true;
}
else p = p->nextsibling;
}
}
else p = p->nextsibling;
}
return false;
}
void xml::allocate()
{
CSNode *p = head->firstChild;
while (p != NULL) {
CSNode *q = p->firstChild;
while (q != NULL) {
CSNode *s = q;
q = q->nextsibling;
if (s->name == "RecvPort") {
cout << "addd" << endl;
}
delete s;
}
CSNode *m = p;
p = p->nextsibling;
delete m;
}
delete head;
}
目前该
程序只能解析3层结构的XML文件