How are attributes parsed in Boost.PropertyTree?

痴心易碎 提交于 2019-12-03 15:08:22

问题


Say I have this XML format:

<Widget type="SomeWidget" name="foo">
   <Event name="onmouseover">
      dostuff();
   </Event>
</Widget>

How do I read the attributes using Boost.PropertyTree?


回答1:


If your problem is to get attributes:

The attributes of an XML element are stored in the subkey . There is one child node per attribute in the attribute node. Existence of the node is not guaranteed or necessary when there are no attributes.

From the doc http://www.boost.org/doc/libs/1_44_0/doc/html/boost_propertytree/parsers.html#boost_propertytree.parsers.xml_parser

So just get them from the xmlattr tag.




回答2:


If xml has such content:

<mode fullscreen="true">mode xxx</mode>

Use boost::property code:

get<string>("mode.<xmlattr>.fullscreen") 

Oh yeah, it's ugly!



来源:https://stackoverflow.com/questions/3690436/how-are-attributes-parsed-in-boost-propertytree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!