Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Boost Property Tree Update Existing Node By Attribute Qualifier

Ok, so here's a sample of the XML structure:

<config>
  <Ignored>
    <Ignore name="Test A">
       <Criteria>
          <value>actual value</value>
       </Criteria>
    </Ignore>
    <Ignore name="Test B">
       <Criteria>
          <value>actual value</value>
       </Criteria>
    </Ignore>
  </Ignored>
<config>

I would like to be able to do two things:

  1. Perform a get directly to the Test A element without having to loop all Ignore elements..like a selector on an attribute.
  2. If nothing else, I need a method of updating either of the Ignore elements and can't seem to figure it out

Do I have to delete the element and recreate it? I can't seem to figure out a way to perform a put which qualifies an element (where there a many with the same name at the same level) by an attribute (which would be unique at that level).

Something like:

pt.put("config.Ignored.Ignore.<xmlattr>.name='Test A'.Criteria.value",some_var)

Or anything else that can achieve the end goal. Thank you very much!

Full disclosure: I'm pretty new to C++ and may be missing something blatantly obvious.

like image 482
CapersL Avatar asked Dec 15 '11 02:12

CapersL


1 Answers

Boost.property_tree xml parser (RapidXML) doesn't support this.
Consider using something like TinyXPath is you want such functionality out of the box.

Or use explicit loop to find Ignore node with required attribute. Then you can use

someIgnoreNode.put("Criteria.value", some_var);
like image 157
Abyx Avatar answered Oct 24 '22 02:10

Abyx