c xml 格式化对齐
来源:互联网 发布:广州数据恢复 价格 编辑:程序博客网 时间:2024/05/23 19:12
程序使用msxml做xml读写。最后保存的时候全都混成一堆。自己写了个简单的xml缩进的函数。只能满足一些简单的格式化需要
std::string PrettyPrint( const char* strSource, const char* strN /*= "\n"*/ )
{
stack<int> stackDeep;
int iLenght = strlen(strSource);
char* strText = (char*)strSource;
char* strStart = strText;
string strXML;
int iNodeNum = 0;
bool bStop = false;
while(*strText)
{
if(*strText == '<')//起始字符
{
strStart = strText;
if(*(strText + 1) == '/')//截止的节点
{
bStop = true;
}
else //起始节点
{
iNodeNum++; //计数本层的
stackDeep.push(iNodeNum);
iNodeNum = 0; //本层次的子节点计0
bStop = false;
}
}
else if(*strText == '>')
{
if(*(strText - 1) == '/')//截止节点
{
bStop = true;
}
string strPrerry = "";
//if(bStop == false || iNodeNum > 1)//存在子节点,换行并且缩进
{
int iSize = (int)stackDeep.size();
//if(iSize > 1)
{
strPrerry += strN;
}
for (int i = 1; i < iSize; i++)
{
strPrerry += " ";
}
}
char cTmp = strText[1];
strText[1] = 0;
strPrerry += strStart;
strText[1] = cTmp;//恢复
strXML += strPrerry;
if(bStop)
{
iNodeNum = stackDeep.top();
stackDeep.pop();
}
bStop = false;
}
++strText;
}
return strXML;
}
- c xml 格式化对齐
- C语言格式化xml
- C语言 printf 格式化 输出 右对齐补零
- C语言 printf /sprintf格式化 输出 右对齐补零
- C语言 printf 格式化 输出 右对齐补零
- C#.net 格式化输出XML文档字符串
- 使用python的minidom模块格式化、对齐、换行、整理xml文件
- 格式化XML
- 格式化xml
- 格式化 XML
- 一个可以格式化输出的XML类(C++)
- Eclipse对齐xml格式
- 【C/C++】内存对齐
- 使用UltraEdit32编辑器格式化源码功能 XML、Java、C/C++、C#
- 格式化缩进XML文档
- 学习XML:格式化内容
- xslt格式化xml文件
- XML的格式化显示
- Unity3D UniRx ReactiveX响应式编程初探1 双击的检测
- PyQuery库使用
- H5页面调用客户端登陆说明----转(收藏)
- 用 Scrapy 抓取某家的楼盘信息
- 贪心,模拟,构造(HDU 5414,CRB and String)
- c xml 格式化对齐
- 第六周错题回顾
- 剑指offer--面试题25:合并两个排序的链表
- POJ-1149 PIGS(最大流)
- 进程和线程的简单解释
- java多线程之间通信
- 用tarjan求割点
- 条件编译与extern "C"
- CodeForces