{"id":18770097,"url":"https://github.com/andreacasalino/xml-parser","last_synced_at":"2026-01-27T12:38:02.014Z","repository":{"id":37026982,"uuid":"171530026","full_name":"andreacasalino/XML-parser","owner":"andreacasalino","description":"Light C++ parser for xml file. You can both import or create from 0 xml structure. ","archived":false,"fork":false,"pushed_at":"2024-09-24T07:23:01.000Z","size":5498,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T22:06:47.942Z","etag":null,"topics":["cpp","export","export-xml","handler","import","import-xml","json","nlohmann","xml"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreacasalino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-19T18:47:43.000Z","updated_at":"2024-09-04T09:27:07.000Z","dependencies_parsed_at":"2025-04-13T07:32:39.057Z","dependency_job_id":"4805d77e-5f21-42ea-a39a-2e27ab1b5712","html_url":"https://github.com/andreacasalino/XML-parser","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andreacasalino/XML-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreacasalino%2FXML-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreacasalino%2FXML-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreacasalino%2FXML-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreacasalino%2FXML-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreacasalino","download_url":"https://codeload.github.com/andreacasalino/XML-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreacasalino%2FXML-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28813215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","export","export-xml","handler","import","import-xml","json","nlohmann","xml"],"created_at":"2024-11-07T19:18:07.825Z","updated_at":"2026-01-27T12:38:01.999Z","avatar_url":"https://github.com/andreacasalino.png","language":"C++","readme":"![binaries_compilation](https://github.com/andreacasalino/XML-parser/actions/workflows/runTests.yml/badge.svg)\n\n- [What is this library about](#intro)\n- [Usage](#usage)\n- [Samples](#samples)\n- [CMake support](#cmake-support)\n- [Conversion to JSON](#conversion-to-json)\n- [XML GUI](#xml-gui)\n\n## INTRO\n\nThis is a light modern **C++** library for managing **xml**. It is possible to **import**, **modify** and **export** any **xml**. At the same time, **xml** can  be **generated from 0** in a programmatic way and later exported over a file or a string.\n\nAll the relevant code is contained under the [src](./src) folder.\nIf you have found this package to be useful, please leave a **star**!\n\n## USAGE\n\nTo parse an **xml** from a file you have just to call one single function:\n```cpp\n#include \u003cXML-Parser/Parser.h\u003e\n\nstd::filesystem::path path = \"aa/bb/cc\";\nauto [metaData, xml_root] = xmlPrs::parseFile(path);\n```\n\nMeta data can be inspected to check the version for example. Notice that the meta data specification is optional for an **xml** and if not provided the meta data collection will be simply empty:\n```cpp\n// extract the version from the metadata ... if provided\nif(auto it_version = metaData.find(\"version\"); it_version != metaData.end()) {\n    const std::string\u0026 version = it_version-\u003esecond;\n    std::cout \u003c\u003c \"version of the doc: \" \u003c\u003c version \u003c\u003c std::endl;\n}\n```\n\nThe parsed **xml** can be inspected in many ways:\n```cpp\nstd::string root_name = xml_root-\u003egetName();\n\n// get the attributes of the root\nconst std::unordered_multimap\u003cstd::string, std::string\u003e\u0026 root_attributes = xml_root-\u003egetAttributes();\n\n// access any tag at a specified path\nstd::filesystem::path nested_path = \"root/childA/childB\";\nxmlPrs::Tag\u0026 nested = xml_root-\u003egetDescendant(nested_path);\n\n// access the attributes of the nested tag\nconst std::unordered_multimap\u003cstd::string, std::string\u003e\u0026 nested_attributes = xml_root-\u003egetAttributes();\n\n// get a subnested tag\nstd::filesystem::path sub_nested_path = \"childC/childD\";\nxmlPrs::Tag\u0026 sub_nested = nested.getDescendant(sub_nested_path);\n```\n\nYou can also generate **xml** structure from scratches, by building an empty root which is later filled (or add something to an already parsed **xml**):\n```cpp\n#include \u003cXML-Parser/Tag.h\u003e\n\nxmlPrs::Tag root{\"Root\"};\n\n// add some attributes\nroot.getAttributes().emplace(\"fieldA\", \"valA\");\nroot.getAttributes().emplace(\"fieldB\", \"valB\");\n\n// add a nested tag\nxmlPrs::Tag\u0026 nested = root.emplaceNested(\"Child\");\n\n// add attributes to the nested child\nnested.getAttributes().emplace(\"fieldC\", \"valC\");\n```\n\nYou can also reprint the generated or modified structure or convert it to a string:\n```cpp\n// print on a file\nstd::ofstream{\"aa/bb/cc/dd\"} \u003c\u003c root;\n\n// ... or convert to a string\nstd::string as_string = xmlPrs::toString(root);\n```\n\n## SAMPLES\n\nHaven't already left a **star**? Do it now! :)!\n\nUnder the [sample](./sample) folder you can find more extensive examples showing you how to use this library.\n\n## CMAKE SUPPORT\n\nHaven't already left a **star**? Do it now! :)!\n\nIn order to consume this library you can rely on **CMake**. This is the way you could integrate this library in your next **CMake** project:\n```cmake\ninclude(FetchContent)\nset(BUILD_XML_Parser_SAMPLES OFF CACHE BOOL \"\" FORCE) # you don't want the samples ... just the library\nFetchContent_Declare(\nxml_parser\nGIT_REPOSITORY https://github.com/andreacasalino/Minimal-Socket\nGIT_TAG        master # or a specific release tag if you want ...\n)\nFetchContent_MakeAvailable(xml_parser)\n```\nThen, you can link to this library in order to use it:\n```cmake\ntarget_link_libraries(THE_TARGET_THAT_NEEDS_TO_CONSUME_XML_PARSER \nPUBLIC \nXML-Parser\n)\n```\n\n## CONVERSION TO JSON\n\nThis package contains also the functionality for automatically converting an **xml** into a **json**. \nMore specifically, a **xmlPrs::Tag** can be automatically converted into a **nlohmann::json** (indeed, the well known [nlohmann josn library](https://github.com/nlohmann/json) is used for the **json** representations):\n```cpp\nxmlPrs::Root as_xml(\"Root\");\n// fill the xml structure\n// ...\n\n// convert to json\nnlohmann::json as_json = as_xml;\n```\n\nCheck also [Example-05](./sample/Example-05.cpp). In that example, this **xml**:\n```xml\n\u003cRoot\u003e\n  \u003cB b=\"val_b\" a=\"val_a1\" a=\"val_a2\"\u003e\n    \u003cD\u003e\u003c/D\u003e\n    \u003cC c=\"val_c\" b=\"val_b\" a=\"val_a\"\u003e\u003c/C\u003e\n    \u003cC c=\"val_c\" b=\"val_b\" a=\"val_a\"\u003e\u003c/C\u003e\n    \u003cC c=\"val_c\" b=\"val_b\" a=\"val_a\"\u003e\u003c/C\u003e\n  \u003c/B\u003e\n  \u003cA b=\"val_b\" a=\"val_a1\" a=\"val_a2\"\u003e\u003c/A\u003e\n\u003c/Root\u003e\n```\n\nis converted to this **json**:\n```json\n{\n \"attributes\": null,\n \"name\": \"Root\",\n \"nested\": {\n  \"A\": {\n   \"attributes\": {\n    \"a\": [\n     \"val_a1\",\n     \"val_a2\"\n    ],\n    \"b\": \"val_b\"\n   },\n   \"name\": \"A\",\n   \"nested\": null\n  },\n  \"B\": {\n   \"attributes\": {\n    \"a\": [\n     \"val_a1\",\n     \"val_a2\"\n    ],\n    \"b\": \"val_b\"\n   },\n   \"name\": \"B\",\n   \"nested\": {\n    \"C\": [\n     {\n      \"attributes\": {\n       \"a\": \"val_a\",\n       \"b\": \"val_b\",\n       \"c\": \"val_c\"\n      },\n      \"name\": \"C\",\n      \"nested\": null\n     },\n     {\n      \"attributes\": {\n       \"a\": \"val_a\",\n       \"b\": \"val_b\",\n       \"c\": \"val_c\"\n      },\n      \"name\": \"C\",\n      \"nested\": null\n     },\n     {\n      \"attributes\": {\n       \"a\": \"val_a\",\n       \"b\": \"val_b\",\n       \"c\": \"val_c\"\n      },\n      \"name\": \"C\",\n      \"nested\": null\n     }\n    ],\n    \"D\": {\n     \"attributes\": null,\n     \"name\": \"D\",\n     \"nested\": null\n    }\n   }\n  }\n }\n}\n```\n\nThis functionality is by default enabled and is controlled by the **CMake** option **ENABLE_XML_Parser_nlohmann_json_converter**. \nWhen set to **ON** (default behaviour), the [**nlohmann**](https://github.com/nlohmann/json) library is fetched in order to allow the conversion. On the contrary case, no external dependency is fetched and the functionality to convert into **json** is not provided.\n\n## XML-GUI\n\nHaven't already left a **star**? Do it now! :)!\n\n[XML-GUI](https://github.com/andreacasalino/XML-GUI) wraps this library as C++ backend to a nice graphical user interactive application handling xml:\n![Example using XML-GUI](https://github.com/andreacasalino/XML-GUI/blob/master/Example.png)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreacasalino%2Fxml-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreacasalino%2Fxml-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreacasalino%2Fxml-parser/lists"}