C++与 xmlwriter 结合使用的列表

发布于 2024-11-27 09:42:02 字数 1211 浏览 2 评论 0原文

我的问题是使用 XmlWriter 在 C++ 中输出列表。我需要一个可以包含在我的 XML 文件中的列表。我计划的代码 - 应该实现一个类来生成列表元素,但我不知道为什么:

writer->WriteStartElement( "Parameters" );

    writer->WriteStartElement( "ParamterList" );
               // A list including approximately 100 entries
               writer->WriteAttributeString( "ID", "001" );
               writer->WriteAttributeString( "Name", "Dummy1" );
               writer->WriteAttributeString( "BitOffset", "0" );
    writer->WriteEndElement();

writer->WriteEndElement();

如何将列表插入到我的应用程序中。我的输出应该是这样的:

<root Name="database" Purpose="test" Project="test">
<Description Version="1.1B" Author="name">test</Description>
<ContainerList>
    <Container Name="Dummy1" BitOffset="0" />
</ContainerList>
<ParameterList>
    <Paramter ID="001" Name="Dummy1" BitOffset="0" />
    <Paramter ID="002" Name="Dummy2" BitOffset="1" />
    <Paramter ID="003" Name="Dummy3" BitOffset="0" />
    <Paramter ID="004" Name="Dummy4" BitOffset="0" />
     ......
</ParameterList>

由于答案1中显示的代码,我现在知道如何将列表与XmlWriter一起使用,但目前我真的不知道如何连接并为此代码编写一个类?

My problem is to output a list in C++ using XmlWriter. I need a list wich can be included in my XML file. My planned code - A class should be implemented to generate the list elements, but I don't know why:

writer->WriteStartElement( "Parameters" );

    writer->WriteStartElement( "ParamterList" );
               // A list including approximately 100 entries
               writer->WriteAttributeString( "ID", "001" );
               writer->WriteAttributeString( "Name", "Dummy1" );
               writer->WriteAttributeString( "BitOffset", "0" );
    writer->WriteEndElement();

writer->WriteEndElement();

How is it possible to insert a list into my application. My output should look like this:

<root Name="database" Purpose="test" Project="test">
<Description Version="1.1B" Author="name">test</Description>
<ContainerList>
    <Container Name="Dummy1" BitOffset="0" />
</ContainerList>
<ParameterList>
    <Paramter ID="001" Name="Dummy1" BitOffset="0" />
    <Paramter ID="002" Name="Dummy2" BitOffset="1" />
    <Paramter ID="003" Name="Dummy3" BitOffset="0" />
    <Paramter ID="004" Name="Dummy4" BitOffset="0" />
     ......
</ParameterList>

Due to the code shown in answer 1, I now know how to use a list with XmlWriter, but at the moment I don't really know how to connect and write a class for this code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-12-04 09:42:02

每个 Paramter (您拼写正确吗?)元素都是一个 XML 元素。因此,它需要一个 WriteStartElement 调用和一个 WriteEndElement。在这些调用中,您可以添加您的 ID 和其他属性。所以你的清单将是这样的:

for (auto listElement :list) //Using C++0x syntax
{
  writer->WriteStartElement( "Paramter" );
  writer->WriteAttributeString( "ID", listElement.id() );
  writer->WriteAttributeString( "Name", listElement.name() );
  writer->WriteAttributeString( "BitOffset", listElement.bitOffset() );
  writer->WriteEndElement();
}

Each Paramter (did you spell that correctly?) element is an XML element. Therefore, it needs a WriteStartElement call and a WriteEndElement. Within those call, you add your IDs and other attributes. So your list would be something like this:

for (auto listElement :list) //Using C++0x syntax
{
  writer->WriteStartElement( "Paramter" );
  writer->WriteAttributeString( "ID", listElement.id() );
  writer->WriteAttributeString( "Name", listElement.name() );
  writer->WriteAttributeString( "BitOffset", listElement.bitOffset() );
  writer->WriteEndElement();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文