Question

im trying to import data from an XML file and save them in a 5D map

// declaration of the map
    map<char *, map<char *, map<char*, map<char *, map<char*, map<char*, char*, cmp_str>, cmp_str>, cmp_str>, cmp_str>, cmp_str>, cmp_str> XmlData;

im using for the XML-Parsing the RapidXML Parser

file<> xmlFile("jobs.xml");
xml_document<> doc;
doc.parse<0>(xmlFile.data());

xml_node<> *node = doc.first_node();
while(node != 0) {
    xml_node<> *child = node->first_node();
    while (child != 0)
    {
       xml_node<> *subchild = child->first_node();
       while (subchild != 0)
       {
           xml_node<> *subsubchild = subchild->first_node();
           while (subsubchild != 0)
           {
               xml_node<> *subsubsubchild = subchild->first_node();
               while (subsubsubchild != 0)
               {
                  // the error appears here
                  XmlData[node->name()][child->name()][subchild->name()][subsubchild->name()][subsubsubchild->name()] = subsubsubchild->value();
                  subsubsubchild = subsubsubchild->next_sibling();
               }
               subsubchild = subsubchild->next_sibling();
           }
           subchild = subchild->next_sibling();
       }
       child = child->next_sibling();
    }
    node = node->next_sibling();
}

I had to use 5 while loops to iterate all nodes

XML :

<Job>
    <UserJob>
        <RuleSet>
            <def>
                <Path>detection_c_new.dcp</Path>
                <WkspName>MyWS</WkspName>
                <UserName>Admin</UserName>
            </def>
        </RuleSet>
    </UserJob>
    <Scenes>
        <Scene1>
            <Info>
                <def>
                    <ID>0</ID>
                    <Name>Scene 1</Name>
                </def>
            </Info>
            <Layers>
                <Layer1>
                    <Index>0</Index>
                    <Name>Layer 1</Name>
                    <ImgPath>CTX_MEM_Detail.jpg</ImgPath>
                </Layer1>
            </Layers>
            <ExpItems>
                <ExpItem1>
                    <Name>MyStats1</Name>
                    <Driver>CSV</Driver>
                    <Type>1</Type>
                        <Path>CTX_MEM_Detail.csv</Path>
                </ExpItem1>
            </ExpItems>
        </Scene1>
    </Scenes>
</Job>

When compiling using g++ with c++0x under CentOS 6 i get this following error:

Job.cpp:133: error: no match for âoperator=â in â((std::map<char*, std::map<char*, char*, cmp_str, std::allocator<std::pair<char* const, char*> > >, cmp_str, std::all$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:251: note: candidates are: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:266: note:                 std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:286: note:                 std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
Was it helpful?

Solution

char* is an awful thing to have as map key, and probably value too.

You might use const char* as key is absolutely sure that you pass pointers to stable things, like literal only.

The baseline soulution would use string as both key and payload, and I guess your problem would go away too. The most probable immediate cause is that your value refuses to convert to char*.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top