से अधिक पुनरावृति करने के लिए मैं की तर्ज पर एक XML संरचना है:कैसे बढ़ावा में XML संरचना :: property_tree
<root>
<SomeElement>
<AnotherElement>
<ElementIWant x="1" y="1"/>
</AnotherElement>
</SomeElement>
<SomeElement>
<AnotherElement>
<ElementIWant x="1" y="1"/>
<ElementIWant x="2" y="1"/>
<ElementIWant x="3" y="1"/>
</AnotherElement>
</SomeElement>
</root>
जो एक boost::property_tree
में पढ़ा जा रहा है, 1..Many<SomeElement>
रों रहे हैं, और फिर उस तत्व के भीतर एक मनमाना गहराई में हो सकता है 1..Many<ElementIWant>
रों
वहाँ आदेश है कि वे appea में <ElementIWant>
सीधे से अधिक पुनरावृति करने के लिए (एक पाश में) एक रास्ता है डॉक्टर में आर?
मैं equal_range
void iterateOverPoints()
{
const char* test =
"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>"
"<SomeElement>"
"<AnotherElement>"
"<ElementIWant x=\"1\" y=\"1\"/>"
"</AnotherElement>"
"</SomeElement>"
"<SomeElement>"
"<AnotherElement>"
"<ElementIWant x=\"1\" y=\"1\"/>"
"<ElementIWant x=\"2\" y=\"1\"/>"
"<ElementIWant x=\"3\" y=\"1\"/>"
"</AnotherElement>"
"</SomeElement>"
"</root>";
boost::property_tree::ptree message;
std::istringstream toParse(test);
boost::property_tree::read_xml(toParse,result_tree);
//Now we need to locate the point elements and set the x/y accordingly.
std::pair< boost::property_tree::ptree::const_assoc_iterator,
boost::property_tree::ptree::const_assoc_iterator > result =
message.equal_range("ElementIWant");
for(boost::property_tree::ptree::const_assoc_iterator it = result.first;
it != result.second; ++it)
{
std::cout << it->first << " : ";
const boost::property_tree::ptree& x = it->second.get_child("<xmlattr>.x");
const boost::property_tree::ptree& y = it->second.get_child("<xmlattr>.y");
std::cout << x.get_value<int>() << "," << y.get_value<int>() << "\n";
}
return;
}
को देखा लेकिन यह नोड्स (जो मुझे लगता है क्योंकि equal_range आपूर्ति पेड़ नोड के स्तर पर काम करता है) कौन सा मेरे ऊपर सवाल के लिए लाता है वापस जाने के लिए असफल रहा है है। ..
क्या आपने 'equal_range (" someElement.AnotherElement.ElementIwant ") का प्रयास किया था;'? निश्चित नहीं है कि कुछ ऐसा होने पर क्या होगा जब कुछ एलीमेंट की दो प्रतियां होंगी। –
अतीत से विस्फोट! @TreborRude मुझे लगता है कि उस समय जिस तरह से मैं चाहता था उसमें व्यवहार नहीं करता था, या यह काम नहीं करता था। शायद पुस्तकालय को ऐसा करने के बाद बढ़ाया गया है - लेकिन मैं इस समय कोड के उस क्षेत्र से बहुत दूर हूं। :) फिर भी सुझाव के लिए धन्यवाद। – Caribou