通过boost向XML添加名称空间 [英] adding namespaces to XML with boost
问题描述
我正在尝试使用boost生成xml。到目前为止一切正常,但是生成的xml需要具有名称空间。
I'm trying to generate an xml using boost. Going fine so far, but the xml that gets generated needs to have a namespace.
所以不是< name> Harry< / name>
而是< ns1:name>哈里< / ns1:name>
是否有任何方法可以将名称空间添加到带有boost的XML而不需要在每行中手动添加 ns1?
Is there any way to add a namespace to the XML with boost without manually adding the "ns1" to every line?
推荐答案
因此,我设法获得了想要的结果。这是我的工作:
So, I managed to get the result I wanted. Here's what I did:
我最外面的元素称为文档:
My outer most element was called 'Document':
ptree& documentnode = pt.add("namespace1:Document", "");
然后为每个命名空间的元素添加标签:
then added tags to the element for each namespace:
pt.add("Document.<xmlattr>.xmlns:namespace1", "value");
然后在每个元素前面添加 namespace1:
Then in front of each element I'll have to add "namespace1":
documentnode.add("namespace1:name", "Harry");
输出:
<namespace1:Document xmlns:namespace1=value>
<namespace1:name>Harry</namespace1:name>
</namespace1:Document>
可能不是最好的解决方案,但它满足了我的需求。
Probably not the best solution, but it suits my needs.
这篇关于通过boost向XML添加名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!