使用xsdcxx树解析器的XSD到C++类.方法从文件中打开xml
XSD to C++ class using xsd cxx-tree parser. Methods to open a xml from a file.
我使用xsd 3.3.0编译器来将xsd(xml最好的朋友)文件解析为C++类。(参见最后一个网络链接)
命令名为
xsd cxx树(选项)文件.xsd
(+信息http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/)
我看到了代码合成提供的一些示例,它们解析hello.xd文档并非常容易地创建.hxx和.cxx文件。.hxx有一个方法来打开一个xml文档,创建一个对象,在那里你可以找到xml的不同部分,检查它,等等。。。.hxx有一个这样的代码:
// Parse a URI or a local file.
//
::std::auto_ptr< ::hello_t >
hello (const ::std::string& uri,
::xml_schema::flags f = 0,
const ::xml_schema::properties& p = ::xml_schema::properties ());
它收到一个文件名为的字符串
字符串&uri="hello.xsd">
并创建您在main.cxx.中使用的对象
因此,我正在尝试对xsd文件执行同样的操作。我使用xsdcxx树编译器,但它没有创建"解析URI或本地文件"的方法。然后我就无法在主程序上从xml文件创建对象。
我使用codesys编译器文档中的不同选项解决了一些编译问题(http://www.codesynthesis.com/projects/xsd/documentation/xsd.xhtml)。关于你想编译什么,你想如何编译,等等,有不同的选项……但我找不到任何选项来启用用于"解析URI或本地文件"的方法。
提供更多的格式,xml xsd文档是CBML协议文档。
谢谢你的帮助!
我自己找到了解决方案!
我使用了不同的编译选项。我使用了选项"--root元素库",这导致没有创建"解析URI或本地文件"的方法。
我删除了这个选项,并添加了"--rootelement-all",它为所有主体对象创建解析方法!
现在我的程序工作了!谢谢
我一直在使用这个产品。
下面是一个你想做的事情的例子(我认为):
xsd cxx-tree hello.xsd
它生成hello.hxx
和hello.cxx
,正如您所说。我认为您的不足之处在于了解如何使用这些文件来加载XML文件(例如,加载"本地文件")。
我喜欢明确地告诉软件在哪里可以找到XSD模式。以下代码将不会编译,但我已将其包含在内以供参考。
void load(const std::string &xml, const std::string &xsd) {
xml_schema::properties properties;
properties.no_namespace_schema_location(xsd);
// or, if you have a specific namespace you want to load, use
// props.schema_location("which namespace", xsd);
try {
std::auto_ptr< ::hello_t> xml_file = hello(xml, 0, props);
// operate on the xml_file via "->" notation
std::cout << xml_file->hello() << std::endl;
} catch (const ::xml_schema::exception &e) {
std::ostringstream os;
os << e.what();
// report the error as you see fit, use os.str() to get the string
}
}
请确保将*.cxx
文件链接到您的*.cpp
文件。
如果这不是你想要的,请在评论中告诉我,我可以尝试帮助你更多。
- 如何使用curlpp通过POST方法上传文件和json数据
- 一种在C++中读取TXT配置文件的简单方法
- 在 cpp 文件中隐藏采用模板参数引用的方法
- 在C++中包含原型文件的正确方法是什么?
- 通过比较C++中的行在 txt 文件中搜索的最简单方法是什么?
- 不带预处理器的调用方法/文件的文件名/行号
- 引用文件的适当方法是什么?
- 在文件中写入而不是在 c++ 中使用 "<<" 的替代方法?
- 查找定义我的 C/C++ 函数/宏的文件比'grep'更简单的方法
- 读取大文件(>2GB)(文本文件包含以太网数据)并通过不同参数随机访问数据的最佳方法是什么?
- 在C++中创建文件夹选取器对话框的最简单方法是什么?
- C++:std::ofstream 方法 open() 在第二次迭代时擦除打开的 ifstream 文件
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 创建进行生产构建并创建调试信息的C++生成文件的最佳方法?
- 是否有正确的方法对生成文件中的对象文件使用模板命令?(C++)
- 将位字符串转储到二进制文件的最佳方法是什么
- 在目录中查找所有.cpp.h文件(include,src等)的传统方法
- 通过boost asio iostream下载大文件的最快方法是什么?
- LNK2019 在文件中调用静态成员的方法时出错.cpp
- 在 *.cpp 文件中实现的 c++ 函数/方法永远不会内联扩展吗?