我正在尝试在 exe 中编写我的程序的配置,如下所示:
<test>
<a1>
<b>100</b>
<c>2</c>
<d>0</d>
</a1>
<a2>
<b>100</b>
<c>2</c>
<d>0</d>
</a2>
</test>
<test2>
<!-- ...-->
</test2>
我正在尝试使用以下代码来做到这一点:
XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( "<a1></a1");
XmlElement^ newElem = doc->CreateElement( "value" );
newElem->InnerText = "105";
doc->DocumentElement->AppendChild( newElem );
newElem = doc->CreateElement( "hotkey" );
newElem->InnerText = "2";
doc->DocumentElement->AppendChild( newElem );
newElem = doc->CreateElement( "enable" );
newElem->InnerText = "0";
doc->DocumentElement->AppendChild( newElem );
doc->LoadXml( "<a2></a2>");
newElem = doc->CreateElement( "value" );
newElem->InnerText = "105";
doc->DocumentElement->AppendChild( newElem );
newElem = doc->CreateElement( "hotkey" );
newElem->InnerText = "2";
doc->DocumentElement->AppendChild( newElem );
newElem = doc->CreateElement( "enable" );
newElem->InnerText = "0";
doc->DocumentElement->AppendChild( newElem );
但第二个 loadXml 优先覆盖,我不知道如何做更多类别。有人可以帮我吗?