我正在使用 Xercesc 来解析 xml 文档。我想知道我将如何使用 XML 值作为程序的输入?
I'm using Xercesc for parsing an xml document. i wanted to know how i'm going to use the xml values as an input for my program?
我使用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>
如何在我的简单程序中使用计数值?
基本上需要遵循的步骤如下:
- 初始化Xerces XMLPlatformUtils
- 初始化Parser并设置其属性
- 使用解析器解析xml文件(parser->parseURI(xmlFile);)
- 一旦解析了文档(DOMDocument),就可以获取根节点,然后使用getChildNodes和getElementsByTagName等函数循环遍历其子节点
您可以从Xerces-c文档中的一些示例开始(http://xerces.apache.org/xerces-c/samples-3.html)。DOMCount示例可能是一个很好的起点。
看起来您需要阅读关于如何从XML文件中获取值的Xerces手册。
从您发布的未注释XML文件中,计数可以是组中的项数,也可以是子组中的项数。
我会循环使用计数或显示它们。还有其他方法可以使用计数值,但我认为您对此不感兴趣。
相关文章:
- 如何使用tinyxml2从XML加载父实体和子实体
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 使用 Tinyxml 在 xml 中添加一个子子项
- 在 c++ 中使用 vtd-xml 时,如何摆脱 EOFException?
- 使用 RapidXML 更新C++中的 XML 节点和属性值
- 使用 libxml2 解析 XML 文件时缺少元素值
- 使用 RapidXML 解析大型 XML(大小大于 65 KB)文件时出现问题
- 如何在 xml 中使用双引号?
- 使用 TinyXML2 读取 C++ 中的 XML 文件
- Xerces-C 使用硬编码的 xsd 验证 xml
- 使用 pugixml 将 xml 命名空间添加到xml_document
- OPENCV - 如何在OpenCV中使用Haar Cascade Github xml文件?
- 如何使用QXmlStreamReader解析包含对其他XML文件的引用的XML文件
- 如何使用libcurl c ++从url保存XML文件
- 尝试使用 RapidXML 将唯一的 XML 属性追加到节点
- 服务器状态到 XML 使用 fwrite?
- 如何使用 Boost XML 解析器
- 如何使用 pugixml 正确访问 xml 属性?
- 如何使用所有其他文件信息来编译代码,例如HAAR级联训练的权重的XML文件
- 将字符串转换为 XML 并使用提升更新值字段