{"id":15044142,"url":"https://github.com/c0stra/fluent-xml-writer","last_synced_at":"2025-10-04T05:31:38.949Z","repository":{"id":57737372,"uuid":"139278978","full_name":"c0stra/fluent-xml-writer","owner":"c0stra","description":"Fluent, hierarchical, streaming XML builder.","archived":true,"fork":false,"pushed_at":"2018-08-09T21:49:27.000Z","size":83,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-29T23:05:53.966Z","etag":null,"topics":["fluent-api","java-8","stream-api","xml"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c0stra.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}},"created_at":"2018-06-30T20:48:26.000Z","updated_at":"2023-10-03T13:01:20.000Z","dependencies_parsed_at":"2022-08-24T02:00:08.373Z","dependency_job_id":null,"html_url":"https://github.com/c0stra/fluent-xml-writer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0stra%2Ffluent-xml-writer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0stra%2Ffluent-xml-writer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0stra%2Ffluent-xml-writer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0stra%2Ffluent-xml-writer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c0stra","download_url":"https://codeload.github.com/c0stra/fluent-xml-writer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235222543,"owners_count":18955327,"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":["fluent-api","java-8","stream-api","xml"],"created_at":"2024-09-24T20:50:08.198Z","updated_at":"2025-10-04T05:31:33.671Z","avatar_url":"https://github.com/c0stra.png","language":"Java","readme":"# Fluent XML writer\n[![Build Status](https://travis-ci.org/c0stra/fluent-xml-writer.svg?branch=master)](https://travis-ci.org/c0stra/fluent-xml-writer)\n\nFluent, hierarchical, XML writer is a tool that should make writing XML data\nprogrammatically convenient and less error prone.\n\n### 1. Streaming\nThis XML writer is streaming. It means, it's not creating any XML document representation in memory, but immediately writes the data to the XML, similarly as XmlStreamWriter. So it's good choice e.g. for XML logging facilities.\n\n### 2. Fluent\nFluent stands for API, that allows chaining. So compared to e.g. `StreamWriter`, you can chain your pieces\nto be written:\n\n```java\ndocument(new FileWriter(\"output.xml\"))\n    .version(1.0).encoding(\"UTF-8\")\n    .tag('root').attribute(\"id\", \"53gf543\")\n        .tag(\"child\")\n            .text(\"My text\")\n        .end()\n    .end()\n.close();\n```\n\n### 3. Hierarchical\nCompared to `StreamWriter`, it is hierarchical. So at any point, the current\nwriter object is stick to certain level and state. This makes following pattern\navailable:\n\n```java\nRootElementWriter root = document(new FileWriter(\"output.xml\"))\n    .tag(\"root\");\n\nroot.tag(\"first\").text(\"first text\");\nroot.tag(\"second\").text(\"second text\");\nroot.finish();\n```\nWith `StreamWriter` similar situation would result in nesting. But with the hierarchical writer\n`root` writer is stick to root element, and thanks to the state it knows, when to close it's\nunclosed children.\n\nResult will be:\n```xml\n\u003croot\u003e\n    \u003cfirst\u003efirst text\u003c/first\u003e\n    \u003csecond\u003esecond text\u003c/second\u003e\n\u003c/root\u003e\n```\nThis makes it again good for XML logging facilities. Because it will always make sure to close any unclosed elements for you.\n\n## User Guide\n\n### 1. Maven dependency\nIn order to use the fluent XML writer, add following dependency to your maven pom.xml:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003efoundation.fluent.api\u003c/groupId\u003e\n    \u003cartifactId\u003efluent-xml-writer\u003c/artifactId\u003e\n    \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### 2. Create XML writer instance\n\nCreate XML writer instances using factory methods:\n\n```java\n// Create writer using default configuration.\nDocumentWriterFactory.document(new FileWriter(\"output.xml\"));\n\n// Create writer with cunstom configuration, e.g. pretty printed with indentation of 4 spaces.\nDocumentWriterFactory.document(new FileWriter(\"output.xml\"), DocumentWriterConfig.config().indentSpaces(4));\n```\n\n### 3. Write document content\n\nFluent API will guide you, how to write the content.\n\nOn the top (document) level you have available methods to define\n- XML version\n- encoding\n- doctype\n- processing instruction\n- text (only if provided with whitespaces)\n\n```java\ndocument(writer).version(1.0).encoding(\"UTF-8\");\n```\n\nYou open element with method `tag(name)`, and specify attributes and namespaces on it.\n```java\ndocument(writer).version(1.0)\n    .tag(\"root\").attribute(\"name\", \"value\")\n    .end();\n```\n\nWithin content you can specify any text, cdata, processing instruction or nested tag.\n\n```java\ndocument(writer).version(1.0)\n    .tag(\"root\")\n        .text(\"Hello\")\n        .cdata(\"Unescaped \u0026\")\n        .tag(\"child\")\n            text(\"Escaped \u0026\")\n        .end()\n    .end();\n```\n\n### 3. Configuration\n\nYou can configure now following things:\n- How attribute values are quoted\n- tag indentation\n- additional attribute indentation (not yet supported)\n```java\n// Quote attributes using single apostrophe\nconfig().singleQuoteValue();\n\n// Quote attributes using double quotes (default)\nconfig().doubleQuoteValue();\n\n// Indent using 4 spaces\nconfig().indentSpaces(4);\n\n// Indent using tab\nconfig().indentUsingTab();\n\n// Indent using 2 tabs\nconfig().indentUsingTabs(2);\n```\n\nConfig uses a fluent API too, so you can chain your directives:\n```java\nconfig().singleQuoteValue().indentSpaces(2);\n```\n\n### 4. Run unit tests on your own\n\nThis project has delivered not only the library, but also a module with tests, which anybody can run\ndirectly from his/her command line.\n\nIt's packaged as Maven plugin, which doesn't require project. So feel free to run the\ntest suite on your own using following command:\n```\nmvn foundation.fluent.api:fluent-xml-writer-tests:1.0:run\n```\n\n## Releases\n\n#### Version 1.0 (August 9th 2018)\n- Support for fluent document level attributes (xml version, encoding, doctype)\n- Support for fluent element definition (tag, attributes, namespaces)\n- Support for fluent element's content creation (text, cdata, processing instructions)\n- Support for keeping hierarchy level (invoking method on an object closes an open child first)\n- Support for escaping special XML characters (\u0026, \u003c, \u003e)\n- Support for handling of invalid XML 1.0 characters\n- Support for pretty printing and custom indentation level","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc0stra%2Ffluent-xml-writer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc0stra%2Ffluent-xml-writer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc0stra%2Ffluent-xml-writer/lists"}