Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
我推荐 MSXML。它可能看起来很复杂,但是当您习惯它时,它会很好而且很容易。这是一个示例:
input.xml:
<?xml version="1.0" encoding="UTF-8"?> <Car> <Wheels> <Wheel1>FL</Wheel1> <Wheel2>FR</Wheel2> <Wheel3>RL</Wheel3> <Wheel4>RR</Wheel4> </Wheels> </Car>
代码:
#include <stdio.h> #include <tchar.h> #include <windows.h> #import <msxml6.dll> rename_namespace(_T("MSXML")) int main(int argc, char* argv[]) { HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { try { MSXML::IXMLDOMDocument2Ptr xmlDoc; hr = xmlDoc.CreateInstance(__uuidof(MSXML::DOMDocument60), NULL, CLSCTX_INPROC_SERVER); // TODO: if (FAILED(hr))... if (xmlDoc->load(_T("input.xml")) != VARIANT_TRUE) { printf("Unable to load input.xml\n"); } else { printf("XML was successfully loaded\n"); xmlDoc->setProperty("SelectionLanguage", "XPath"); MSXML::IXMLDOMNodeListPtr wheels = xmlDoc->selectNodes("/Car/Wheels/*"); printf("Car has %u wheels\n", wheels->Getlength()); MSXML::IXMLDOMNodePtr node; node = xmlDoc->createNode(MSXML::NODE_ELEMENT, _T("Engine"), _T("")); node->text = _T("Engine 1.0"); xmlDoc->documentElement->appendChild(node); hr = xmlDoc->save(_T("output.xml")); if (SUCCEEDED(hr)) printf("output.xml successfully saved\n"); } } catch (_com_error &e) { printf("ERROR: %ws\n", e.ErrorMessage()); } CoUninitialize(); } return 0; }
输出:XML 已成功加载汽车有 4 个轮子output.xml 已成功保存
output.xml:
<?xml version="1.0" encoding="UTF-8"?> <Car> <Wheels> <WheelLF>1</WheelLF> <WheelRF>2</WheelRF> <WheelLR>3</WheelLR> <WheelRR>4</WheelRR> </Wheels> <Engine>Engine 1.0</Engine></Car>
您将在这里找到所需的一切:http://msdn.microsoft.com/en- us/library/ms765540(v=vs.85).aspx
希望有人觉得这很有用;)
I recommend MSXML. It may look complicated, but it's nice and easy when you get used to it.Here's a sample:
input.xml:
code:
output:XML was successfully loadedCar has 4 wheelsoutput.xml successfully saved
output.xml:
You will find everything you need here:http://msdn.microsoft.com/en-us/library/ms765540(v=vs.85).aspx
Hope someone finds this useful ;)
Boost 序列化器可以做到这一点,如果您将一个对象传递给它,它会写入一个包含所有类属性的文件(二进制或 xml,甚至简单的文本文件)。
Boost serializer can do the trick, if you pass an object to it, it write a file (binary or xml or even a simple text file) with all the class properties.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
我推荐 MSXML。它可能看起来很复杂,但是当您习惯它时,它会很好而且很容易。
这是一个示例:
input.xml:
代码:
输出:
XML 已成功加载
汽车有 4 个轮子
output.xml 已成功保存
output.xml:
您将在这里找到所需的一切:
http://msdn.microsoft.com/en- us/library/ms765540(v=vs.85).aspx
希望有人觉得这很有用;)
I recommend MSXML. It may look complicated, but it's nice and easy when you get used to it.
Here's a sample:
input.xml:
code:
output:
XML was successfully loaded
Car has 4 wheels
output.xml successfully saved
output.xml:
You will find everything you need here:
http://msdn.microsoft.com/en-us/library/ms765540(v=vs.85).aspx
Hope someone finds this useful ;)
Boost 序列化器可以做到这一点,如果您将一个对象传递给它,它会写入一个包含所有类属性的文件(二进制或 xml,甚至简单的文本文件)。
Boost serializer can do the trick, if you pass an object to it, it write a file (binary or xml or even a simple text file) with all the class properties.