{"id":16485393,"url":"https://github.com/zaid-ajaj/fable.simplexml","last_synced_at":"2025-03-23T12:32:58.423Z","repository":{"id":30567095,"uuid":"116643032","full_name":"Zaid-Ajaj/Fable.SimpleXml","owner":"Zaid-Ajaj","description":"A library for easily parsing and working with XML in Fable projects","archived":false,"fork":false,"pushed_at":"2023-01-07T13:40:35.000Z","size":1431,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T00:41:17.500Z","etag":null,"topics":["fable","parser","xml","xml-parser"],"latest_commit_sha":null,"homepage":"https://zaid-ajaj.github.io/Fable.SimpleXml/","language":"F#","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/Zaid-Ajaj.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-01-08T07:16:26.000Z","updated_at":"2024-03-27T04:22:39.000Z","dependencies_parsed_at":"2023-01-14T17:13:47.547Z","dependency_job_id":null,"html_url":"https://github.com/Zaid-Ajaj/Fable.SimpleXml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FFable.SimpleXml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FFable.SimpleXml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FFable.SimpleXml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FFable.SimpleXml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zaid-Ajaj","download_url":"https://codeload.github.com/Zaid-Ajaj/Fable.SimpleXml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244297871,"owners_count":20430347,"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":["fable","parser","xml","xml-parser"],"created_at":"2024-10-11T13:25:46.543Z","updated_at":"2025-03-23T12:32:58.005Z","avatar_url":"https://github.com/Zaid-Ajaj.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fable.SimpleXml [![Build Status](https://travis-ci.org/Zaid-Ajaj/Fable.SimpleXml.svg?branch=master)](https://travis-ci.org/Zaid-Ajaj/Fable.SimpleXml) [![Build Status](https://ci.appveyor.com/api/projects/status/s3esn08o7d4ehlm1?svg=true)](https://ci.appveyor.com/project/Zaid-Ajaj/fable-simplexml) [![Nuget](https://img.shields.io/nuget/v/Fable.SimpleXml.svg?maxAge=0\u0026colorB=brightgreen)](https://www.nuget.org/packages/Fable.SimpleXml)\n\nA simple library for parsing Xml strings into structured Xml data. Works in browser and node without installing any extra javascript dependencies. It is written using parser combinators from [Fable.Parsimmon](https://github.com/Zaid-Ajaj/Fable.Parsimmon)\n\n\n### See the library in action in the [Test page](https://zaid-ajaj.github.io/Fable.SimpleXml/)\n\n\n### Installation\nInstall from nuget using paket\n```sh\npaket add nuget Fable.SimpleXml --project path/to/YourProject.fsproj\n```\nMake sure the references are added to your paket files\n```sh\n# paket.dependencies (solution-wide dependencies)\nnuget Fable.SimpleXml\n\n# paket.refernces (project-specific dependencies)\nFable.SimpleXml\n```\n\n### Example usage\n```fs\ntype Person = { Id : int; Name: string }\n\nlet createPerson id name =\n    { Id = id; Name = name }\n\n\"\"\"\n\u003cPeople\u003e\n    \u003cPerson Id=1 Name='John' /\u003e\n    \u003cPerson Id='2' Name=\"Jane\" /\u003e\n\u003c/People\u003e\n\"\"\"\n|\u003e SimpleXml.parseElement\n|\u003e SimpleXml.findElementsByName \"Person\"\n|\u003e List.map (fun elem -\u003e\n    let id = int (Map.find \"Id\" elem.Attributes)\n    let name = Map.find \"Name\" elem.Attributes\n    createPerson id name)\n```\nOr you can inspect the content of the elements:\n```fs\ntestCase \"SimpleXml use case\" \u003c| fun test -\u003e\n    \"\u003cPeople\u003e\n        \u003cPerson\u003eJohn\u003c/Person\u003e\n        \u003cPerson\u003eJane\u003c/Person\u003e\n    \u003c/People\u003e\"\n    |\u003e SimpleXml.parseElementNonStrict\n    |\u003e SimpleXml.children\n    |\u003e List.map SimpleXml.content\n    |\u003e test.areEqual [ \"John\"; \"Jane\" ]\n```\n### API\n\n```fs\n// Parsing functions\nSimpleXml.tryParseElement : string -\u003e Option\u003cXmlElement\u003e\nSimpleXml.parseElement : string -\u003e XmlElement\nSimpleXml.tryParseDocument : string -\u003e Option\u003cXmlDocument\u003e\nSimpleXml.parseDocument : string -\u003e XmlDocument\n\n// Non strict parsing functions, exludes text nodes between elements (leaving Content intact)\nSimpleXml.parseElementNonStrict : string -\u003e XmlElement\nSimpleXml.tryParseElementNonStrict : string -\u003e Option\u003cXmlElement\u003e\nSimpleXml.tryParseDocumentNonStrict : string -\u003e Option\u003cXmlDocument\u003e\nSimpleXml.parseDocumentNonStrict : string -\u003e XmlDocument\n\n// Search functions\nSimpleXml.findElementsBy : (XmlElement -\u003e bool) -\u003e XmlElement -\u003e XmlElement list\nSimpleXml.findElementsByName : string -\u003e XmlElement -\u003e XmlElement list\nSimpleXml.findElementByName : string -\u003e XmlElement -\u003e XmlElement\nSimpleXml.findElementsByExactAttributes : Map\u003cstring, string\u003e -\u003e XmlElement -\u003e XmlElement list\nSimpleXml.findElementByAttribute : string -\u003e string -\u003e XmlElement -\u003e XmlElement list\nSimpleXml.tryFindElementByAttributes : Map\u003cstring, string\u003e -\u003e XmlElement -\u003e Option\u003cXmlElement\u003e\nSimpleXml.tryFindElementByName : string -\u003e XmlElement -\u003e Option\u003cXmlElement\u003e\n/// ... AND MORE ...\n```\n\nWhere `XmlElement` and `XmlDocument` are defined as follows:\n```fs\ntype XmlElement = {\n    Namespace : string option\n    Name : string\n    Attributes : Map\u003cstring, string\u003e\n    Content : string\n    Children : XmlElement list\n    SelfClosing : bool\n    IsTextNode : bool\n    IsComment : bool\n}\n\ntype XmlDocument = {\n    Declaration : Map\u003cstring, string\u003e option\n    Root : XmlElement\n}\n```\n\n### Generate Xml:\nCreate Xml from a tree structure. Opening the `Fable.SimpleXml.Generator` module, gives you access to these:\n - `node`: creates a nested element\n - `leaf`: creates a self-closing element\n - `text`: creates a terminal node with text\n - `comment`: creates a comment\n - `namespace`: adds a namespace prefix to a `node` or a `leaf`\n - `attr.value`: create an attribute\n - `ofXmlElement`/`ofXmlElements`: Can be used to convert a `XmlElemnt` to a Xml tree\n - `serializeXml`: converts a Xml tree to a xml string\n\n\u003e Indentation is not supported yet. PR's are welcome ;)\n\n```fs\nopen Fable.SimpleXml.Generator\n\nlet people =\n    node \"people\" [ ] [\n        leaf \"person\" [\n            attr.value(\"name\", \"John Doe\")\n            attr.value(\"age\", 26)\n            attr.value(\"married\", false)\n        ]\n\n        leaf \"person\" [\n            attr.value(\"name\", \"Jane Doe\")\n            attr.value(\"age\", 25)\n            attr.value(\"married\", true)\n        ]\n    ]\n\nserializeXml people\n```\nwill generate:\n```xml\n\u003cpeople\u003e\n  \u003cperson name=\"John Doe\" age=\"26\" married=\"false\" /\u003e\n  \u003cperson name=\"Jane Doe\" age=\"25\" married=\"true\" /\u003e\n\u003c/people\u003e\n```\n\nUse nested property\n```fs\nlet person =\n    node \"person\" [ ] [\n        node \"id\" [ ] [ text \"1\" ]\n        node \"name\" [ ] [ text \"John\" ]\n        node \"married\" [ ] [ text \"false\" ]\n    ]\n\nserializeXml person\n```\nwill generate\n```xml\n\u003cperson\u003e\n    \u003cid\u003e1\u003c/id\u003e\n    \u003cname\u003eJohn\u003c/name\u003e\n    \u003cmarried\u003efalse\u003c/married\u003e\n\u003c/person\u003e\n```\n\nAccess any xml to update/change it\n```fs\nlet xml =\n    \"\"\"people\u003e\n        \u003cperson name=\"John Doe\" age=\"26\" married=\"false\" /\u003e\n        \u003cperson name=\"Jane Doe\" age=\"25\" married=\"true\" /\u003e\n    \u003c/people\u003e\"\"\"\n\nlet parsedXml = SimpleXml.parseElement xml\n\n// .. Work with the xml by removing, changing, adding any xml element or attribute including comments and namespaces. ..\n\n// Revert XmlElement back to xml string\n\nlet xmlTree = Generator.ofXmlElement parsedXml\n\nserializeXml xmlTree\n```\n\n### Running sample app locally\n```sh\n./build.sh RunSample\n#or\nbuild RunSample\n```\n### Running the tests live\n```sh\n./build.sh RunLiveTests\n```\n### Building the tests and running QUnit cli runner\n```sh\n./build.sh RunTests\n```\nor just `Ctrl + Shift + B` to run the cli tests as a VS Code task","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaid-ajaj%2Ffable.simplexml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaid-ajaj%2Ffable.simplexml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaid-ajaj%2Ffable.simplexml/lists"}