0

I have a text file with the following data format

 <create>
    <way id="-200341" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-106862"/>
      <nd ref="-106343"/>
      <nd ref="-107240"/>
      <nd ref="-107241"/>
      <nd ref="-106863"/>
      <nd ref="-106858"/>
      <nd ref="-106866"/>
      <nd ref="-106263"/>
      <nd ref="-106868"/>
      <nd ref="-106857"/>
      <nd ref="-107242"/>
      <nd ref="-106867"/>
      <nd ref="-106865"/>
      <nd ref="-107243"/>
      <nd ref="-107244"/>
      <nd ref="-106864"/>
      <tag k="shelter" v="yes"/>
      <tag k="highway" v="footway"/>
    </way>
    <way id="-200340" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-106853"/>
      <nd ref="-106852"/>
      <tag k="shelter" v="yes"/>
      <tag k="highway" v="footway"/>
    </way>
    <way id="-200277" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-106228"/>
      <nd ref="8236806130"/>
      <tag k="highway" v="footway"/>
    </way>
    <way id="-200253" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-106766"/>
      <nd ref="-106765"/>
      <nd ref="-106226"/>
      <nd ref="-106769"/>
      <nd ref="-106228"/>
      <nd ref="-106773"/>
      <nd ref="-106230"/>
      <nd ref="-106771"/>
      <nd ref="-106768"/>
      <tag k="highway" v="footway"/>
      <tag k="shelter" v="yes"/>
    </way>
    <way id="-200219" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-107148"/>
      <nd ref="-106747"/>
      <tag k="shelter" v="yes"/>
      <tag k="highway" v="footway"/>
    </way>
    <way id="-200218" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-106766"/>
      <nd ref="-106755"/>
      <tag k="shelter" v="yes"/>
      <tag k="highway" v="footway"/>
    </way>
    <way id="-200066" version="0" timestamp="1970-01-01T00:00:00Z">
      <nd ref="-106755"/>
      <nd ref="-107148"/>
      <nd ref="-106760"/>
      <nd ref="-106764"/>
      <nd ref="-106762"/>
      <nd ref="-107115"/>
      <nd ref="-106197"/>
      <tag k="highway" v="footway"/>
      <tag k="shelter" v="yes"/>
    </way>
    <way id="543558082" version="1" timestamp="2017-11-29T19:30:02Z" uid="0" user="">
      <nd ref="1314909074"/>
      <nd ref="5254615443"/>
      <nd ref="5254615442"/>
      <nd ref="5254615441"/>
      <nd ref="5254615440"/>
      <nd ref="-106516"/>
      <nd ref="5254615439"/>
      <nd ref="5254615438"/>
      <nd ref="5254615437"/>
      <nd ref="5254615436"/>
      <nd ref="5254615435"/>
      <tag k="service" v="driveway"/>
      <tag k="highway" v="service"/>
      <tag k="oneway" v="yes"/>
    </way>

I have a unordered_map std::unordered_map<int, std::string> uMapID_feats{}; declared like this.

Assuming that my map has all of these ID numbers ref="XXXXX" numbers stored, and a defaulted string stored in it, like "unknownplace".

what I want to do is map the ID (called "ref=XXXXXX") to the tags that are listed under it. So the tags eg. for the first ID ref=106862, the tags that are connected to it are 200341, shelter, highway, footway, yes

So in the map, the first 3 pairs would look like this:

"106862" , "200341,shelter,highway,footway,yes"  
"106343" , "200341,shelter,highway,footway,yes"
"107240" , "200341,shelter,highway,footway,yes"

Some sets have more tags than others and some have only 2 tags, hence why I would like it all to be written to a string and stored in this unordered_map, the tags separated by commas.

How should I go about parsing this data and getting it stored in the unordered_map correctly?

any help is appreciated, thank you!

Muzammil Ismail
  • 303
  • 4
  • 9
Megan Darcy
  • 530
  • 5
  • 15
  • 1
    To save the hassle of parsing XML correctly, consider using a library. Something like [pugixml](https://pugixml.org/) would probably be sufficient, and being a header-only library it's very easy to integrate into any project. Then you can just focus on how you want to store and process the data without getting bogged down by XML syntax. – paddy Oct 28 '21 at 05:27
  • thanks @paddy but this syntax is slightly different from an XML file, as when i try to use pugixml, there are issues as this is a .osc file.... do you know any libraries for .osc files? thanks – Megan Darcy Oct 28 '21 at 08:15
  • The example text you show looks like it can be parsed as XML to me. Exactly what about the syntax is "slightly different"? Are you referring to there being no schema or document tag? When you say there are "issues", what issues exactly? And if "OSC" is a popular format, what is the full description and purpose of the format and where is its specification? I'm pretty sure you're not talking about either Open Sound Control, nor Outlook Social Connector. Is this something related to Open Street Map? – paddy Oct 28 '21 at 09:40
  • it's an open street map change file, thanks. – Megan Darcy Oct 28 '21 at 12:06
  • You still haven't described why you can't parse this as XML. I looked at the Open Street Map Wiki for that format and it doesn't look like there is anything remotely special about it at all. – paddy Oct 28 '21 at 12:46

1 Answers1

1

Use an xml parsing Library like plugixml, or you could build your own one.

There are many libraries which parses xml. Chose the one which fits your needs. This may help you: What XML parser should I use in C++?

ihsan
  • 365
  • 3
  • 11