我过去使用 RapidXML 时遇到的问题很少,但这个问题让我很困惑。
我正在创建应用程序事件时间戳的日志,外部程序可以在重播中读取原始应用程序中在正确时间发生的任何音频。
在初始化应用程序时,会正确生成以下 XML:
<?xml version="1.0" encoding="utf-8"?>
<playbacklog>
<logitem type="general" event="start" timestamp="85639323"/>
</playbacklog>
添加下一项后,文档将变为:
<?xml version="1.0" encoding="utf-8"?>
<playbacklog>
<logitem type="general" event="start" timestamp="NUL NUL NUL NUL"/>
<logitem type="audio" event="start" timestamp="86473833">
</playbacklog>
接着:
<?xml version="1.0" encoding="utf-8"?>
<playbacklog>
<logitem type="general" event="start" timestamp="@NUL NUL' NUL NUL"/>
<logitem type="audio" event="start" timestamp="NUL NUL NUL NUL">
<logitem type="audio" event="stop" timestamp="8654533">
</playbacklog>
随着每个新的开始和停止对的添加,还可以看到最终的以下行为,所有具有相同事件属性值的节点的时间戳值都发生了变化:
<?xml version="1.0" encoding="utf-8"?>
<playbacklog>
<logitem type="general" event="start" timestamp="@NUL NUL' NUL NUL"/>
<logitem type="audio" event="start" timestamp="NUL NUL NUL NUL">
<logitem type="audio" event="stop" timestamp="8674519">
<logitem type="audio" event="start" timestamp="NUL NUL NUL NUL">
<logitem type="audio" event="stop" timestamp="8674519">
<logitem type="audio" event="start" timestamp="NUL NUL NUL NUL">
<logitem type="audio" event="stop" timestamp="8674519">
</playbacklog>
我在 c++ 头文件中这样声明文档:
private:
rapidxml::xml_document<> outputDocument;
为了创建每个节点,我使用以下代码:
// tStamp is a typedef'd std::pair containing two std::string values, one for the
// time at which the evet occurred and the other containing the event type.
void AudioLogger::LogEvent( Timestamp* tStamp )
{
rapidxml::xml_node<>* nodeToAdd = outputDocument.allocate_node(rapidxml::node_element, "logitem");
...
nodeToAdd->append_attirbute(outputDocument.allocate_attribute("timestamp", ts->first.c_str()));
...
outputDocument.first_node()->next_sibling()->append_node(nodeToAdd);
}
传递给此函数的 TimeStamp* 值保存在 std::vector 中,当添加新值时,将调用此函数。
如果有人对这里发生的事情有任何想法,那将是一个巨大的帮助。另外,如果需要更多信息,我也可以提供。