0

Now I'm using tinyxml2 library for merge several xml files. I want to checking xml files in same folder(I will use absolute path). And when I combine several xml files, I will remove the duplicates and merge them by comparing the values of Firstchild Element and its first attribute.

I tried many cases, but not sure about which can be merged in an accurate and fast way. Now I will show what I want to get.

  • First xml file

    <?xml version='1.0' encoding='utf-8'?> 
    <osm version="0.6" generator="    ">
      <node id="147782" visible="true" version="1" />
      <node id="147788" visible="true" version="1" />
      <node id="147794" visible="true" version="1" />
      <node id="147829" visible="true" version="1" />
      <node id="147835" visible="true" version="1" />
      <node id="147843" visible="true" version="1" />
      <node id="147850" visible="true" version="1" />
      <way id="10808" visible="true" version="1">
        <nd ref="147788" />
        <nd ref="150133" />
        <nd ref="150145" /> 
      </way>
      <way id="10824" visible="true" version="1">
        <nd ref="156232" />
        <nd ref="156240" />
        <nd ref="156251" />
      </way>
    
  • Second xml file

    <?xml version='1.0' encoding='utf-8'?>
    <osm version="0.6" generator="    ">
      <node id="147843" visible="true" version="1" />
      <node id="147850" visible="true" version="1" />
      <node id="438198" visible="true" version="1" />
      <node id="438199" visible="true" version="1" />
      <way id="10808" visible="true" version="1">
        <nd ref="147788" />
        <nd ref="150133" />
        <nd ref="150145" />
      </way>
      <way id="10821" visible="true" version="1">
        <nd ref="153211" />
        <nd ref="153230" />
        <nd ref="153243" />
      </way>
    
  • Merged xml file

     <?xml version='1.0' encoding='utf-8'?>
     <osm version="0.6" generator="    "> 
      <node id="147782" visible="true" version="1" />
      <node id="147788" visible="true" version="1" />
      <node id="147794" visible="true" version="1" />
      <node id="147829" visible="true" version="1" />
      <node id="147835" visible="true" version="1" />
      <node id="147843" visible="true" version="1" />
      <node id="147850" visible="true" version="1" />
      <node id="438198" visible="true" version="1" />
      <node id="438199" visible="true" version="1" />
      <way id="10808" visible="true" version="1">
        <nd ref="147788" />
        <nd ref="150133" />
        <nd ref="150145" />
      </way>
      <way id="10824" visible="true" version="1">
        <nd ref="156232" />
        <nd ref="156240" />
        <nd ref="156251" />
      </way>
      <way id="10821" visible="true" version="1">
        <nd ref="153211" />
        <nd ref="153230" />
        <nd ref="153243" /> 
      </way>
    

Like that Merged xml file, I want merge them without overlapping. In those case, it can be compare with node id and way id.

I'm sorry if my question sounded ambiguous. If there is something wrong, I will correct it as soon as possible.

Markus
  • 1
  • 1
  • 1
    Please share your attempt to fix the problem. We help people who try hard and fail, not people who simply ask. You got to sweat before you ask. – Gabriel Mar 09 '21 at 09:11
  • Am I mistaken or do those `XML` files require a root element? – Galik Mar 09 '21 at 10:56
  • @Galik In those case, I just scan root element's first attribute(id). I forgot first root element. Now I tried to success get those attribute, but node root and way root are the same level so it is impossible to distinguish between the two. for(tinyxml2::XMLElement* child1 = doc.FirstChildElement("osm")->FirstChildElement("node"); child1 != 0; child1 = child1->NextSiblingElement()){ if(child1->ToElement()->Attribute("id")) std::cout << "id = " << child1->ToElement()->Attribute("id") << std::endl;} – Markus Mar 10 '21 at 00:26
  • Mayb try something like: `doc.RootElement()->FirstChildElement("node");`. Also edit the question to correct the `XML` files to have a root element. – Galik Mar 10 '21 at 00:58
  • @Galik Ok, I will try that case which you recommend to me. Thank you :) – Markus Mar 10 '21 at 04:31
  • @Galik I resolved thta problem! I thought root element was not important, but it wasn't. It was the starting point for me to distinguish in the way I wanted. Thank you and have a nice day! – Markus Mar 17 '21 at 04:20

0 Answers0