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?
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?
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>
key in the path.
BOOST_FOREACH(ptree::value_type &v, pt.get_child("widget.xmlattr")) attributes.insert(std::make_pair(v.first.data(), v.second.data())
do? –
Onus 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!
<mode fullscreen="true">mod xxx</mod>
does not appear to be well-formed xml. –
Porcia 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>
key in the path.
BOOST_FOREACH(ptree::value_type &v, pt.get_child("widget.xmlattr")) attributes.insert(std::make_pair(v.first.data(), v.second.data())
do? –
Onus © 2022 - 2024 — McMap. All rights reserved.