boost生成xml與tinyxml之間的格式轉換

2021-10-07 08:37:44 字數 2612 閱讀 3515

#ifndef __simulation_structures_h_

#define __simulation_structures_h_

#include

#include

"boost\serialization\vector.hpp"

#include

"boost\archive\xml_oarchive.hpp"

#include

"boost\archive\xml_iarchive.hpp"

using

namespace std;

class

bowei_para

double a;

double b;

double c;

double d;

template

<

class

archive

>

void

serialize

(archive& archive,

const

unsigned

int version)};

//轉換頭檔案 turnxml.h

#pragma once

#include

#include

#include

#include

#include

#include

"tinystr.h"

#include

"tinyxml.h"

#include

#include

"string.h"

#include

"boost\serialization\vector.hpp"

#include

"boost\archive\xml_oarchive.hpp"

#include

"boost\archive\xml_iarchive.hpp"

#include

"struct.h"

#include

"turnxml.h"

using

namespace std;

bowei_para bowei;

intturnxml_s

(string file_add)

tixmlhandle hdoc

(&document)

; tixmlelement* ement = hdoc.

firstchildelement()

.element()

;//指向根節點

tixmlhandle hroot

(ement)

;// hroot是根節點

//signature 沒有讀

//進入 bowei_para

ement = ement-

>

firstchildelement()

;//進入 bowei 的子節點 a

ement = ement-

>

firstchildelement()

; bowei.a =

strtod

(ement-

>

gettext()

,null);

//atoi(ement->gettext())轉換成整數

//atof(ement->gettext())轉換成浮點數,double型別

//strtod(ement->gettext(), null);double型別

//strtof(ement->gettext(), null);float型別

//進入 bowei 的子節點b

ement = ement-

>

nextsiblingelement()

; bowei.b =

strtod

(ement-

>

gettext()

,null);

//進入 bowei 的子節點c

ement = ement-

>

nextsiblingelement()

; bowei.c=

strtod

(ement-

>

gettext()

,null);

//進入 bowei 的子節點d

ement = ement-

>

nextsiblingelement()

; bowei.d =

atoi

(ement-

>

gettext()

);//boost開始寫

std::ofstream file

(file_add)

; boost::archive::xml_oarchive oa

(file)

; oa &

boost_serialization_nvp

(bowei)

;return1;

//生成名字為bowei的節點,然後在該節點下生成a,b,c,d四個子節點

}

BOOST 解析,修改,生成xml樣例

解析iworld xml,拿到entity和visiblevolume的資料 int parseiworlds readxml const bpath dir catch const std exception e ptree ptchild pt.get child world.levels.le...

使用Boost讀取xml

boost中提供了對配置檔案讀取的支援,它就是 property tree。basic ptree 是property tree的核心基礎。其介面像std list。可以執行很多基本的元素操作,比如使用begin end 等。此外還加入了操作屬性樹的get get child get value d...

XML的解析與生成

1.寫布局 2.業務邏輯 a.備份 1.封裝簡訊資料到list中 2.將list中的資料寫到xml檔案中。b.恢復 1.解析xml檔案中簡訊資料,封裝到list集合中 2.將解析資料列印。xmlserializer 使用xmlserializer來序列化xml檔案 public static boo...