I am new to xml. I am trying to read an xml file taken from openstreetmaps. it looks as follow
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
<bounds minlat="48.3994690" minlon="9.9897780" maxlat="48.3998220" maxlon="9.9898260"/>
<node id="149248718" lat="48.3994984" lon="9.9897961" user="Matthias Frank" uid="287306" visible="true" version="7" changeset="7966729" timestamp="2011-04-25T18:01:43Z"/>
<node id="1831376336" lat="48.3995041" lon="9.9898087" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:51Z"/>
<node id="1831376346" lat="48.3995599" lon="9.9902392" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376331" lat="48.3993243" lon="9.9898198" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:51Z"/>
<node id="1831376349" lat="48.3996127" lon="9.9906471" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376348" lat="48.3996044" lon="9.9910549" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376418" lat="48.4000685" lon="9.9897909" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:55Z"/>
<node id="1831376350" lat="48.3996158" lon="9.9908451" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376374" lat="48.3999450" lon="9.9897917" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:54Z"/>
<way id="172207897" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:59Z">
<nd ref="1831376348"/>
<nd ref="1831376350"/>
<nd ref="1831376349"/>
<nd ref="1831376346"/>
<nd ref="1831376336"/>
<tag k="bicycle" v="yes"/>
<tag k="highway" v="living_street"/>
<tag k="name" v="Hintere Rebengasse"/>
<tag k="oneway" v="yes"/>
</way>
<way id="172207928" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:03:01Z">
<nd ref="1831376331"/>
<nd ref="1831376336"/>
<nd ref="1831376374"/>
<nd ref="1831376418"/>
<tag k="bicycle" v="yes"/>
<tag k="highway" v="living_street"/>
<tag k="name" v="Pfauengasse"/>
<tag k="oneway" v="yes"/>
</way>
</osm>
What is the the simplest and shortest way to read the the data e.g. from node i want to read id, lat, lon and for each node I want to save that information as well. also for elements as "way" I want to read the ref and "tag" elements attached to it.
I am using simple fstream but it doesn't look the most efficient way.
please help
Instead of inventing the wheel again you could and should use a XML parser:
http://lars.ruoff.free.fr/xmlcpp/
For light weight parsing I usually use RapidXml. It's fast and is easy to use (at least from my point of view)
You should use an XML parsing library. Which one is up to you. Currently, I'm looking at tinyxml but I haven't used it yet so I can't endorse it. It does look very simple to incorporate into a project though.
Related
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!
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++?
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.
I'm trying to customizing in WSO2 Governance Registry 4.6.0 (G-Reg) the "Service List" table (Home > Metadata > List > Services) adding two column from "Service detail view": "Overview - Description" and "Endpoints - URL"
I've edited the "Services Artifacts" (Home > Extensions > Configure > Artifact Types > Artifact Source) with the following lines:
<artifactType type="application/vnd.wso2-service+xml" shortName="service" singularLabel="Service" pluralLabel="Services" hasNamespace="false" iconSet="27">
<storagePath>/trunk/services/#{namespace}/#{name}</storagePath>
<nameAttribute>overview_name</nameAttribute>
<!--<endpoint1Attribute>endpointstext_endpoint1</endpoint1Attribute>-->
<namespaceAttribute>overview_namespace</namespaceAttribute>
<lifecycle>ServiceLifeCycle</lifecycle>
<ui>
<list>
<column name="Service Name B">
<data type="text" value="overview_name"/>
</column>
<!-- NEW Description -->
<column name="Description">
<data type="text" value="overview_description"/>
</column>
<!-- NEW Endpoints -->
<column name="Endpoints">
<!-- <data type="text" value="endpoints_endpoint1"/> -->
<!-- <data type="text" value="endpointmgt_endpointstext_endpoint1"/> -->
<data type="text" value="endpoints_endpointstext_endpoint1"/>
</column>
<column name="Service Version">
<data type="path" value="overview_version" href="#{storagePath}"/>
</column>
<column name="Service Namespace">
<data type="text" value="overview_namespace"/>
</column>
</list>
</ui>
<content>
......
</content>
</artifactType>
The column "Descrition" is filled properly, while column "Endpoints" is empty.
How to value the tag value?(data type="text" value="???????"/>) ??
You can not add unbounded table values to list view. But if you really want see the endpoint value in the list create a new text filed and replicate the same value.
<list>
<column name="Service Name">
<data type="text" value="overview_name"/>
</column>
<column name="Service Version">
<data type="path" value="overview_version" href="#{storagePath}"/>
</column>
<column name="Service Namespace">
<data type="text" value="overview_namespace"/>
</column>
<column name="Endpoint">
<data type="text" value="endpoints_endpoint"/>
</column>
</list>
and update the endpoints table like below
<table name="Endpoints">
<subheading>
<heading>Environments</heading>
<heading>URL</heading>
</subheading>
<field type="option-text" maxoccurs="unbounded" url="true">
<name label="Endpoint">Endpoint</name>
<values>
<value>None</value>
<value>Unknown</value>
<value>Dev</value>
<value>Test</value>
<value>Stag</value>
<value>Prod</value>
</values>
</field>
<field type="text">
<name label="Endpoint">Endpoint</name>
</field>
</table>
Now you can see endpoint value in the list.
To create your own RXTs please find this article.
i have a simple xml text like this:
<BTree Version="4">
<Node Type="SEL" ID="1" Description="rootNode">
<Node Type="SEL" ID="2" Description="enterNode">
<Node Type="SEQ" ID="9" Description="Birth">
<Node Type="ACTION" ID="5073" EditorData="2" Name="TipsNode">
<Param Name="Tips" Type="str" Value="drive"/>
</Node>
</Node>
</Node>
<Node Type="SEL" ID="3" Description="exitNode"/>
<Node Type="SEL" ID="4" Description="execNode"/>
</Node>
</BTree>
i want to save it as binary file, and then read it.(for some reason, i have to do this)
i am not going to use Binary XML protocol such as Efficient XML Interchange(an implementation would be EMIP). because it is too heavy.
here is what i want:
1.is there any light library(open source,c++) that does this work for me?
2.if there is not, my consideration is implementing this by saving struct to binary file.each node of the xml is a struct. but how to deal with the attribute of the xml noe? i mean
there are different attributes and they are generally optional, how can i define the struct so that there is not memory waste.
I am getting an error when adding a new record to a new artifact type I created. The error is as follows
failed to add/edit artifact details. A valid qualified name was not set for this artifact
I created a new artifact type called 'Domain'. The artifact type was added but I cannot add new records to it. Get the same error as above when I add new record to Domain artifact type. My xml is attached.
<?xml version="1.0"?>
<artifactType type="application/vnd.wso2-domain+xml" shortName="domain" singularLabel="Domain" pluralLabel="Domains" hasNamespace="false" iconSet="9">
<storagePath>/domains/#{overview_domain}/#{overview_parentname}/domain</storagePath>
<nameAttribute>overview_domain</nameAttribute>
<ui>
<list>
<column name="Domain">
<data type="text" value="overview_domain"/>
</column>
<column name="Parent Domain">
<data type="text" value="overview_parentname"/>
</column>
</list>
</ui>
<content>
<table name="Domain">
<field type="options" required="true">
<name label="Domain Name">Domain Name</name>
<values>
<value>Research</value>
<value>Development</value>
<value>Medicine</value>
<value>Marketing and Sales</value>
<value>Operations</value>
<value>Enabling Functions</value>
<value>Communications</value>
<value>Human Resources</value>
<value>Finance</value>
<value>Legal</value>
<value>Purchasing</value>
<value>Information Systems</value>
</values>
</field>
<field type="options">
<name label="Parent Domain Name">Parent Domain Name</name>
<values>
<value/>
<value>Research</value>
<value>Development</value>
<value>Medicine</value>
<value>Marketing and Sales</value>
<value>Operations</value>
<value>Enabling Functions</value>
<value>Communications</value>
<value>Human Resources</value>
<value>Finance</value>
<value>Legal</value>
<value>Purchasing</value>
<value>Information Systems</value>
</values>
</field>
</table>
</content>
</artifactType>
Also I want to know if there is a thorough document describing how to add artifact types and records. As an example I added a storage path called
/domains/#{overview_domain}/#{overview_parentname}/domain
but I do not know where this points to and if this is even valid or not. The documentation in the online help is not adequate enough to add new artifact structures and records.
Thanks
Under the <ui> tag you have listed two columns. The value attribute given to each column must be in the format {basetable}_{fieldname}
Therefor the names given under each <field> must match with the value <data attribute= of corresponding <column> under <ui>.
To get rid of the error, change the name of the first field to be "Domain" so that it matches with the name that you have given in the column(i.e. overview_domain). So that the tag of the first should look like
<name label="Domain Name">Domain</name>
You should do the same for the second field too, so that the of second field must look as follows
<name label="Parent Domain Name">ParentName</name>
Kindly find the corrected domain.rxt.
To create your own RXTs please find this article.
<?xml version="1.0"?>
<artifactType type="application/vnd.wso2-domain+xml" shortName="domain" singularLabel="Domain" pluralLabel="Domains" hasNamespace="false" iconSet="9">
<storagePath>/domains/#{overview_domain}/#{overview_parentname}/domain</storagePath>
<nameAttribute>overview_domain</nameAttribute>
<ui>
<list>
<column name="Domain">
<data type="text" value="overview_domain"/>
</column>
<column name="Parent Domain">
<data type="path" value="overview_parentname" href="#{storagePath}"/>
</column>
</list>
</ui>
<content>
<table name="Overview">
<field type="options" required="true">
<name label="Domain Name">domain</name>
<values>
<value>Research</value>
<value>Development</value>
<value>Medicine</value>
<value>Marketing and Sales</value>
<value>Operations</value>
<value>Enabling Functions</value>
<value>Communications</value>
<value>Human Resources</value>
<value>Finance</value>
<value>Legal</value>
<value>Purchasing</value>
<value>Information Systems</value>
</values>
</field>
<field type="options">
<name label="Parent Domain Name">parentname</name>
<values>
<value/>
<value>Research</value>
<value>Development</value>
<value>Medicine</value>
<value>Marketing and Sales</value>
<value>Operations</value>
<value>Enabling Functions</value>
<value>Communications</value>
<value>Human Resources</value>
<value>Finance</value>
<value>Legal</value>
<value>Purchasing</value>
<value>Information Systems</value>
</values>
</field>
</table>
</content>
</artifactType>