{"id":24954905,"url":"https://github.com/simy4/xpath-to-xml","last_synced_at":"2025-04-10T17:29:05.056Z","repository":{"id":42681075,"uuid":"93243087","full_name":"SimY4/xpath-to-xml","owner":"SimY4","description":"XML builder library based on XPath processing","archived":false,"fork":false,"pushed_at":"2024-10-29T22:06:49.000Z","size":3400,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"2.x","last_synced_at":"2024-10-30T00:39:11.257Z","etag":null,"topics":["dom","dom4j","gson","jackson","java","jdom2","json","json-api","scala","scala-xml","xml","xml-model","xom","xpath"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimY4.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}},"created_at":"2017-06-03T11:11:40.000Z","updated_at":"2024-10-29T22:06:17.000Z","dependencies_parsed_at":"2023-10-23T10:40:22.226Z","dependency_job_id":"6729d789-4277-40c3-9a8a-3960374c161c","html_url":"https://github.com/SimY4/xpath-to-xml","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimY4%2Fxpath-to-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimY4%2Fxpath-to-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimY4%2Fxpath-to-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimY4%2Fxpath-to-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimY4","download_url":"https://codeload.github.com/SimY4/xpath-to-xml/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236892817,"owners_count":19221241,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dom","dom4j","gson","jackson","java","jdom2","json","json-api","scala","scala-xml","xml","xml-model","xom","xpath"],"created_at":"2025-02-03T05:17:32.919Z","updated_at":"2025-04-10T17:29:05.049Z","avatar_url":"https://github.com/SimY4.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XPath-to-XML\n[![Build Status](https://github.com/SimY4/xpath-to-xml/actions/workflows/build-and-test.yml/badge.svg?branch=2.x)](https://github.com/SimY4/xpath-to-xml/actions?query=workflow%3A%22Build+and+Test%22\")\n[![codecov](https://codecov.io/gh/SimY4/xpath-to-xml/branch/2.x/graph/badge.svg)](https://codecov.io/gh/SimY4/xpath-to-xml)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.github.simy4.xpath/xpath-to-xml-core.svg)](https://search.maven.org/search?q=g:com.github.simy4.xpath)\n[![Javadocs](http://www.javadoc.io/badge/com.github.simy4.xpath/xpath-to-xml-core.svg)](http://www.javadoc.io/doc/com.github.simy4.xpath/xpath-to-xml-core)\n\nConvenient utility to build XML models by evaluating XPath expressions.\n\n# Supported XML models\n\n - DOM\n - DOM4J\n - JDOM\n - Scala XML\n - XOM\n \n## Additionally supported models\n\n - jakarta.json\n - Gson\n - Jackson\n\n# Usage\n\nInclude an artifact with necessary model extension into your project:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.simy4.xpath\u003c/groupId\u003e\n    \u003cartifactId\u003expath-to-xml-dom\u003c/artifactId\u003e\n    \u003cversion\u003e2.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nNow having a XML structure i.e.:\n\n```xml\n\u003cbreakfast_menu\u003e\n    \u003cfood\u003e\n        \u003cname\u003eBelgian Waffles\u003c/name\u003e\n        \u003cprice\u003e$5.95\u003c/price\u003e\n        \u003cdescription\u003eTwo of our famous Belgian Waffles with plenty of real maple syrup\u003c/description\u003e\n        \u003ccalories\u003e650\u003c/calories\u003e\n    \u003c/food\u003e\n\u003c/breakfast_menu\u003e\n```\n\nand one of supported models:\n\n```java\nimport java.io.StringReader;\nimport javax.xml.parsers.*;\n\nimport org.xml.sax.InputSource;\n\nclass Example0 {\n  private static final String xmlSource = \"my-xml-source\";\n\n  public static Document document(String xml) throws Exception {\n    var documentBuilderFactory = DocumentBuilderFactory.newInstance();\n    var documentBuilder = documentBuilderFactory.newDocumentBuilder();\n    var inputSource = new InputSource(new StringReader(xml));\n    return documentBuilder.parse(inputSource);\n  }\n}\n```\n\nyou can:\n\n- alter existing paths\n\n```java\nimport com.github.simy4.xpath.XmlBuilder;\n\nclass Example1 extends Example0 { \n    public static void main(String... args) throws Exception {\n        new XmlBuilder()\n                .put(\"/breakfast_menu/food[1]/price\", \"$7.95\")\n                .build(document(xmlSource));\n    }\n}\n```\n\n- append new elements\n\n```java\nimport com.github.simy4.xpath.XmlBuilder;\n\nclass Example2 extends Example0 { \n    public static void main(String... args) throws Exception {\n        new XmlBuilder()\n                .put(\"/breakfast_menu/food[name='Homestyle Breakfast'][price='$6.95'][description='Two eggs, bacon or sausage, toast, and our ever-popular hash browns']/calories\", \"950\")\n                .build(document(xmlSource));\n    }\n}\n```\n\n- remove paths\n\n```java\nimport com.github.simy4.xpath.XmlBuilder;\n\nclass Example3 extends Example0 { \n    public static void main(String... args) throws Exception {\n        new XmlBuilder()\n                .remove(\"/breakfast_menu/food[name='Belgian Waffles']\")\n                .build(document(xmlSource));\n    }\n}\n```\n\n- combine any of the above actions into a single modification action\n\n```java\nimport com.github.simy4.xpath.XmlBuilder;\n\nclass Example4 extends Example0 { \n    public static void main(String... args) throws Exception {\n        new XmlBuilder()\n                .remove(\"/breakfast_menu/food[name='Homestyle Breakfast']\")\n                .put(\"/breakfast_menu/food[name='Homestyle Breakfast'][price='$6.95'][description='Two eggs, bacon or sausage, toast, and our ever-popular hash browns']/calories\", \"950\")\n                .build(document(xmlSource));\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimy4%2Fxpath-to-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimy4%2Fxpath-to-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimy4%2Fxpath-to-xml/lists"}