我正在使用Xercesc来解析xml文档。我想知道我将如何使用xml值作为我程序的输入?
我不想使用“cin”我希望从中解析值 xml文件
include "stdafx.h"
#include <iostream>
using namespace std;
void Print(int count, int countSub, int rolePerGroup, int userCount, int userPerGroup)
{
for(int roleCount = 1; roleCount<=rolePerGroup; roleCount ++)
{
if(userPerGroup == 0)
{
cout<<"Parent groups are: "<< count <<" | "<<"Sub group are : "<<countSub<<" | "<<"Role per Sub group are : "<< roleCount <<" | "<<"User per role are : "<< userCount <<endl;
continue;
}
for(userCount = 1; userCount<=userPerGroup; userCount ++)
cout<<"Parent groups are: "<< count <<" | "<<"Sub group are : "<<countSub<<" | "<<"Role per Sub group are : "<< roleCount <<" | "<<"User per role are : "<< userCount <<endl;
}
}
int main()
{
int userCount = 0;
int roleCount = 0;
int parentGroup;
cout<<"enter a number of parentGroup"<< endl;
cin>> parentGroup;
if (parentGroup == 0)
{
cout<<"Parent Group should not be zero"<<endl;
exit(EXIT_FAILURE);
}
int subGroup;
cout<<"enter a number sub Group"<< endl;
cin>> subGroup;
int rolePerGroup;
cout<<"enter a number role per Sub Group"<< endl;
cin>> rolePerGroup;
if (rolePerGroup == 0)
{
cout<<"Role per Group should not be zero"<<endl;
exit(EXIT_FAILURE);
}
int userPerGroup;
cout<<"enter a number user per Role"<< endl;
cin>> userPerGroup;
for(int count=1;count <= parentGroup; count ++)
{
if(subGroup == 0)
{
Print( count, 0, rolePerGroup, userCount, userPerGroup);
continue;
}
for(int countSub = 1;countSub<=subGroup; countSub ++)
{
Print( count, countSub, rolePerGroup, userCount, userPerGroup);
}
}
}
我想用于简单解析的Xml是:
<organizationFile>
<ParentGroup>
<Count>15</Count>
<SubGroup>
<Count>3</Count>
<Role>
<Count>15</Count>
<User>
<Count>3</Count>
</User>
</Role>
</SubGroup>
</Group>
</organizationFile>
如何在简单程序中使用计数值?
答案 0 :(得分:0)
看起来您需要阅读Xerces手册,了解如何从XML文件中获取值。
从您发布的未注释的 XML文件中,计数可以是组中的项目数或子组中的项目数。
我会在循环中使用计数或显示它们。还有其他方法可以使用计数值,但我不认为你对它们感兴趣。
答案 1 :(得分:0)
基本上您需要遵循的步骤如下:
您可以从查看Xerces-c文档(http://xerces.apache.org/xerces-c/samples-3.html)中的一些示例开始。 DOMCount示例可能是一个很好的起点。