【发布时间】:2014-02-18 13:41:47
【问题描述】:
我正在尝试创建 XML 签名机制。 我的 XML 可能如下所示:
<Main>
<ChildType1>... </ChildType1>
<ChildType2>... </ChildType2>
</Main>
事实上,它与Main 节点下的数据类型无关。
我只想计算包含在Main 节点中的数据的CRC,然后在Main 上添加signature 属性。
但现在我写了
ostringstream ss;
{
boost::archive::text_oarchive oa(ss);
ss.str("");
try
{
TiXmlBase::SetCondenseWhiteSpace(false);
tinyxml::Document doc;
doc.LoadFile(filename.c_str());
tinyxml::Element* schemes = tinyxml::findSingleElement<SchemesSignatureException>(doc, "Main");
if (schemes == 0) throw logica_error("No Main found");
tinyxml::TinyXmlFwdIterator<tinyxml::Element> child;
for (child = child.begin(schemes); child != child.end(); ++child)
{
//the question is here, how to get the XML text of each child of the Main...
}
}
catch (exception& e)
{
throw ;
}
}
string data(ss.str());
boost::crc_32_type crc;
crc.process_bytes(data.data(), data.size());
当我遍历孩子时,如何获取 XML 文本字符串,例如,第一次迭代将刷新 oa 中的“...”,第二次迭代将刷新 oa 中的“...”?
我试过 GetText 但它总是返回 NULL ! 你有什么想法吗?
【问题讨论】:
-
在
TiXmlElement对象上调用GetText()应该检索元素的文本。你用的是什么版本的 tinyxml? -
我没有在源代码中看到您引用的数据类型(
tinyxml::Element),所以看起来您必须做一些额外的事情。在TiXmlElement上调用GetText()是正确的用法。 -
感谢您的帮助,事实上我使用了一些命名空间别名,所以这就是我的代码与 tinyXML API 不匹配的原因。但最后我解决了我的问题。