{"id":20755209,"url":"https://github.com/formix/damn-simple-xml","last_synced_at":"2025-04-28T18:06:23.306Z","repository":{"id":20224363,"uuid":"23496144","full_name":"formix/damn-simple-xml","owner":"formix","description":"XML serialization library aiming to simplify a programmer's life","archived":false,"fork":false,"pushed_at":"2015-08-05T17:51:26.000Z","size":853,"stargazers_count":8,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T18:06:17.909Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formix.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":"2014-08-30T16:49:03.000Z","updated_at":"2024-01-09T10:26:34.000Z","dependencies_parsed_at":"2022-08-22T15:40:14.627Z","dependency_job_id":null,"html_url":"https://github.com/formix/damn-simple-xml","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2Fdamn-simple-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2Fdamn-simple-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2Fdamn-simple-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2Fdamn-simple-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formix","download_url":"https://codeload.github.com/formix/damn-simple-xml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251362151,"owners_count":21577403,"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":[],"created_at":"2024-11-17T09:23:50.043Z","updated_at":"2025-04-28T18:06:23.283Z","avatar_url":"https://github.com/formix.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Stories in Ready](https://badge.waffle.io/formix/damn-simple-xml.png?label=ready\u0026title=Ready)](https://waffle.io/formix/damn-simple-xml)\ndamn-simple-xml [![travis-ci build result](https://api.travis-ci.org/formix/damn-simple-xml.svg?branch=master \"damn-simple-xml master\")](https://travis-ci.org/search/damn-simple-xml)\n===============\n\n[![Join the chat at https://gitter.im/formix/damn-simple-xml](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/formix/damn-simple-xml?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nDams Simple XML DSX is optimized to serialize JavaScript objects and deserialize \nXML elements that have been formerly serialized from an object in another \nprogramming language (or by DSX). DSX is not designed to handle any kind of \nfree form XML documents. DSX have a small memory footprint. It is the only \nXML library that can handle CDATA sections for both serialization and \ndeserialization.\n\n[Google Group](https://groups.google.com/forum/?hl=fr#!forum/damn-simple-xml)\n\n## Documentation and Release Notes\n\nConsult the full [API Reference](https://github.com/formix/damn-simple-xml/wiki/Api-Reference) for detailed documentation.\n\nConsult The [Release Notes](https://github.com/formix/damn-simple-xml/wiki/Release-Notes) here.\n\n## Usage\n\nThe following usage scenarios are oversimplified. with DSX, you can fine tune \nand control each serialization behaviors. You can choose to define a field to be \nserialized as an attribute, a CDATA or define a collection child \nelements' name. For more informations, see \n[API Reference](https://github.com/formix/damn-simple-xml/wiki/Api-Reference) \nreference\n\n### Serialization\n\nBy default, all fields of an object will be serialized as a XML element. You\ncan control serialization by providing a `behavior` object telling Damn \nSimple Xml how to serialize attributes texts, CDATA, arrays and arrays' \nitems fields:\n\n```javascript\nvar Serializer = require(\"damn-simple-xml\");\nvar serializer = new Serializer();\n\nvar employees = [\n  { \n    id: 123,\n    department: \"Marketting\",\n    fullname: \"John Doe\",\n    emails: [\n        {\n            type: \"home\",\n            value: \"jd@home.com\"\n        },\n        {\n            type: \"work\",\n            value: \"jd@work.com\"\n        }\n    ]\n  },\n  { \n    id: 456,\n    department: \"Administration\",\n    fullname: \"Jane Dowell\",\n    emails: [\n        {\n            type: \"home\",\n            value: \"jane_dowell@home.com\"\n        }\n    ]\n  }\n];\n\nvar xml = \"\";\nserializer.serialize({\n  name: \"employees\", \n  data: employees\n}, function(err, xmlpart, level) {\n  if (err) {\n    console.log(err);\n    return;\n  }\n  xml += xmlpart;\n  if (level === 0) {  // 0 means seialization is done\n    console.log(xml);\n  }\n});\n```\n\nThe previous code will result in a one line unformatted xml corresponding to:\n\n```xml\n\u003cemployees\u003e\n  \u003cemployee\u003e\n    \u003cid\u003e123\u003c/id\u003e\n    \u003cdepartment\u003eMarketting\u003c/department\u003e\n    \u003cfullname\u003eJohn Doe\u003c/fullname\u003e\n    \u003cemails\u003e\n      \u003cemailsItem\u003e\n        \u003ctype\u003ehome\u003c/type\u003e\n        \u003cvalue\u003ejd@home.com\u003c/value\u003e\n      \u003c/emailsItem\u003e\n      \u003cemailsItem\u003e\n        \u003ctype\u003ework\u003c/type\u003e\n        \u003cvalue\u003ejd@work.com\u003c/value\u003e\n      \u003c/emailsItem\u003e\n    \u003c/emails\u003e\n  \u003c/employee\u003e\n  \u003cemployee\u003e\n    \u003cid\u003e456\u003c/id\u003e\n    \u003cdepartment\u003eAdministration\u003c/department\u003e\n    \u003cfullname\u003eJane Dowell\u003c/fullname\u003e\n    \u003cemails\u003e\n      \u003cemailsItem\u003e\n        \u003ctype\u003ehome\u003c/type\u003e\n        \u003cvalue\u003ejane_dowell@home.com\u003c/value\u003e\n      \u003c/emailsItem\u003e\n    \u003c/emails\u003e\n  \u003c/employee\u003e\n\u003c/employees\u003e\n```\n\n### Deserialization\n\nWhen unspecified, free text beside other XML elements is added to the \"_text\"\nfield by default.\n\nGiven the following XML:\n```xml\n\u003cemployee\u003e\n  This employee is terrible!\n  \u003cfirstName\u003eJohn\u003c/firstName\u003e\n  \u003clastName\u003eDoe\u003c/lastName\u003e\n  \u003cemails\u003e\n    \u003cemail type=\"work\"\u003ejdoe@work.com\u003c/email\u003e\n    \u003cemail type=\"personal\"\u003ejohn.doe@nobody.com\u003c/email\u003e\n  \u003cemails\u003e\n\u003c/employee\u003e\n```\n\n```javascript\nvar Serializer = require(\"damn-simple-xml\");\nvar serializer = new Serializer();\n\nserializer.deserialize(xml, function(err, root) {\n  console.log(root);\n});\n```\n\nWill display the following Javascritp object:\n\n```javascript\n{\n  name: \"employee\",\n  data: {\n    _text: \"This employee is terrible!\",\n    firstName: \"John\",\n    lastName: \"Doe\",\n    emails: [\n      {\n        type: \"work\",\n        value: \"jdoe@work.com\"\n      },\n      {\n        type: \"personal\",\n        value: \"john.doe@nobody.com\"\n      }\n    ]\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformix%2Fdamn-simple-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformix%2Fdamn-simple-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformix%2Fdamn-simple-xml/lists"}