利用STAF调用STAX解析XML来执行脚本

前端之家收集整理的这篇文章主要介绍了利用STAF调用STAX解析XML来执行脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

STAF里面封装了好多的数据类型,最奇怪的是STAFString类型。但是大致过程是先注册STAF的服务,会返回一个唯一的id号,高大上的说法叫句柄handle。然后就是按照STAFHandle中的命令格式去设置字段的值,最后就是submit一下提交命令,STAF默认返回值是0的情况下是正常的,STAF API Return Code Reference.html开发文档里有各种错误的返回码,可以作为参考,但是一般不太准,RT。。。。然后就可以等待结果了,贴下简单的代码

#include "STAF.h"
#include "STAF_iostream.h"
#pragma comment(lib,"D:/STAF/lib/STAF.lib");

int main()
{
	STAFHandlePtr handlePtr;
	unsigned int rc = STAFHandle::create("STAF/stax",handlePtr);
	if (rc != 0)
	{
		cout << "Error regestering with STAF,RC: " << rc << endl;
		return rc;
	}

	STAFString machine = STAFString("local");
	STAFString process = STAFString("stax");
	STAFString command = STAFString("EXECUTE FILE ");
	STAFString filename = STAFString("D:/mystax.xml");
//	cin >> filename;
	
	cout << STAFHandle::wrapData(command) << endl;
	STAFResultPtr res = handlePtr->submit(machine,process,command + filename);

	if(res-> rc != kSTAFOk)
	{
		cout << "Process start request Failed with rc=" << STAFString(res->rc);
		cout << "Result=" << res->result << endl;
		return res->rc;
	}
	return 0;

}

mystax.xml文件里的内容
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="main"/>
<function name = "main">
<process>
<location>'local'</location>
<command>'notepad'</command>
</process>
</function>
</stax>
原文链接:https://www.f2er.com/xml/298929.html

猜你在找的XML相关文章