1. 程式人生 > >pugixml 解析類操作xml 支援xpath

pugixml 解析類操作xml 支援xpath

官網和下載地址

不廢話,直接上文件中的例子吧!! 從文件中載入xml檔案,另外這個解析類很強大,

另外注意一點,在vs編譯的時候需要將pugixml.cpp 去掉預編譯!

//tree.xml
<?xml version="1.0"?>
<mesh name="mesh_root">
	<!-- here is a mesh node -->
	some text
	<![CDATA[someothertext]]>
	some more text
	<node attr1="value1" attr2="value2" />
	<node attr1="value2">
		<innernode/>
	</node>
</mesh>
<?include somedata?>



#include "pugixml.hpp"

#include <iostream>

int main()
{
// tag::code[]
    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file("tree.xml");

    std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl;
// end::code[]
}

// vim:et