problem mit boost::property_tree



  • hi,

    ich versuche ein xml file zu parsen und verwende boost::property_tree und bekomme folgende exception beim ausfuehren des folgenden codes:

    <unspecified file>(1): expected <
    

    kann boost das format nicht lesen?

    std::string input = "/home/manfredo/testcase.xml";
    std::stringstream ss;
    ss << input;
    using boost::property_tree::ptree;
    ptree pt;
    read_xml(ss, pt);
    

    ausschnitt meines xml files:

    <?xml version="1.0" encoding="UTF-8"?>
    <testCase uUID="_UaaRANm3EeOxacrzyXMxuQ" generationDate="2014-05-12T11:25:12.336" version="5.1.1">
      <generationStrategy name="Default Strategy" description="Strategy's description" uUID="_opgF4dToEeOZTrl2Y4HCsA">
        <profile name="Default profile" description="" uUID="_on-b4dToEeOZTrl2Y4HCsA"/>
        <algorithm name="User Oriented + Filter" description="description" uUID="uUID">
          <parameters>
    


  • Die Bibliothek ist jedenfalls nicht dazu gedacht, beliebige XML-Dateien zu lesen. XML ist nur eine Möglichkeit, wie ein "Property Tree" abgespeichert werden kann. Das XML, was Du da lesen willst, ist wohl kein "Property Tree".



  • Please note that RapidXML does not understand the encoding specification. If you pass it a character buffer, it assumes the data is already correctly encoded; if you pass it a filename, it will read the file using the character conversion of the locale you give it (or the global locale if you give it none). This means that, in order to parse a UTF-8-encoded XML file into a wptree, you have to supply an alternate locale, either directly or by replacing the global one.

    Hat die Datei ein BOM? Würde ich mal entfernen.



  • problem behoben:

    string file = "/home/manfredo/testcase.xml";
    read_xml(file, pt);
    
    ich habe folgede xml structur, wie kann ich nun die attribute fuer input extrahieren?
    <foo id ="1" version="5.2">
    	<config name="default" id="0.2"/>
    	<bar>
    		<input name="init1" number="1"/>
                    <input name="init2" number="2"/>
                    <input name="test3" number="3"/>
    	</bar>
    	<bar>
    		<input name="test1" number="1"/>
    	</bar>
    </foo>
    

    mit folgenden code kann ich schon mal ueber alle config und bar iterieren:

    BOOST_FOREACH( boost::property_tree::ptree::value_type const& v, pt.get_child("foo") ) {
       std::cout << v.first << std::endl;
    }
    

    wie kann ich ueber alle input attribute iterieren?


Anmelden zum Antworten