gpt4 book ai didi

c++ - XML 类描述到 C++ 类描述 : a design pattern?

转载 作者:行者123 更新时间:2023-11-28 07:36:37 25 4
gpt4 key购买 nike

<分区>

我想知道是否有针对这种情况的特定设计模式(可能针对 C++)。

我有一个包含以下格式数据的 XML 文件:

<STH_XML>
<tag1>
<tag2 id="myId1">
<tag3 name="type" value="myVal1"/>
<tag4 name="device" value="myVal2"/>
<tag5 name="instances" value="myVal3"/>
<tag6>
<tag7 id="myId2">
<specs name="type" value="myVal4"/>
<specs name="frequency" value="myVal5" unit="MHz"/>
</tag7>
</tag6>
</tag2>
</tag1>

不幸的是,此 XML 的 XSD/DTD 经常更改。

我需要像这样自动将 XSD/DTD 转换成一系列 C++ 结构或类:

struct tag7
{
std::string id;
std::string type;
std::string frequency;
}

struct tag6
{
std::set<tag7*> tag6s;
}

struct tag2
{
std::string id;
std::string type;
std::string device;
std::string instances;
tag6 elem6; // because I know there is only one from the XSD analysis
}

struct tag1
{
std::set<tag2> tag2s;
}

哪种设计模式最适合实现此功能?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com