{"id":21997726,"url":"https://github.com/osfunapps/os-xml-handler-npm","last_synced_at":"2026-04-17T17:32:35.700Z","repository":{"id":98762592,"uuid":"206505076","full_name":"osfunapps/os-xml-handler-npm","owner":"osfunapps","description":"This module will build, read and manipulate an xml file. Other handy stuff is also available, like search for a specific nodes.","archived":false,"fork":false,"pushed_at":"2021-02-07T15:08:33.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T04:45:12.730Z","etag":null,"topics":["filehandler","npm","osfunapps","xml"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osfunapps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-09-05T07:44:24.000Z","updated_at":"2021-02-07T15:08:35.000Z","dependencies_parsed_at":"2023-05-25T05:30:36.102Z","dependency_job_id":null,"html_url":"https://github.com/osfunapps/os-xml-handler-npm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/osfunapps/os-xml-handler-npm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osfunapps%2Fos-xml-handler-npm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osfunapps%2Fos-xml-handler-npm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osfunapps%2Fos-xml-handler-npm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osfunapps%2Fos-xml-handler-npm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osfunapps","download_url":"https://codeload.github.com/osfunapps/os-xml-handler-npm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osfunapps%2Fos-xml-handler-npm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31938735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["filehandler","npm","osfunapps","xml"],"created_at":"2024-11-29T22:17:53.619Z","updated_at":"2026-04-17T17:32:35.678Z","avatar_url":"https://github.com/osfunapps.png","language":"JavaScript","readme":"Introduction\n------------\n\nThis module will build, read and manipulate an xml files. Other handy stuff is also available, like \nsearch for a specific nodes.\n \n\n## Installation\nInstall via npm:\n    \n    npm i os-xml-file-handler\n\n\n## Functions and signatures:\n```js\n/**\n* Will create an xml file to work with.\n* Notice: this method WON'T save the xml in the system. To save the xml, call saveXml(xml)\n*\n* @param rootNodeTag -\u003e the tag name of the root node\n*/\ncreateXml: function (rootNodeTag) {\n    return self.loadXml(null, '\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\\n\u003c' + rootNodeTag + '/\u003e')\n},\n\n\n/**\n * Will save any changes made in the xml\n *\n * @param xml -\u003e the xml\n * @param filePath -\u003e the output path of the file\n */\nsaveXml: function (xml, filePath) {\n    let xmlStr = xml.write({'xml_declaration': true});\n    streamer.writeFileSync(xmlStr, filePath)\n},\n\n/**\n * Will load an xml file\n *\n * @param fromPath -\u003e optional path to the xml file\n * @param fromStr -\u003e optional xml string\n */\nloadXml: async function (fromPath, fromStr = null) {\n    let xmlStr = fromStr;\n    if (xmlStr === null) {\n        let xmlInLines = await streamer.readFile(fromPath);\n        xmlStr = xmlInLines.join(\"\\n\");\n    }\n    return et.parse(xmlStr);\n},\n\n/**\n * Will add a node to a certain (relative) location\n *\n * @param xml -\u003e the xml file\n * @param nodeTag -\u003e the tag for the new node ('String', for example)\n * @param attDict -\u003e optional dict of att and values for the new node\n * @param nodeText -\u003e optional text the new node will carry\n * @param parentNode -\u003e (optional) the parent of the new node (for root descendent, leave blank)\n */\naddNode: function (xml, nodeTag, attDict = {}, nodeText = null, parentNode = null) {\n\n    if(parentNode === null) {\n        parentNode = self.getRoot(xml)\n    }\n\n    let element = et.SubElement(parentNode, nodeTag, attDict);\n\n    if(nodeText !== null) {\n        self.setNodeText(element, nodeText)\n    }\n\n    return element\n},\n\n/**\n * Will return a list of nodes specified by an attribute key and and an attribute value.\n *\n * @param xml -\u003e the xml object\n * @param node_tag -\u003e the tag of the nodes to look for\n * @param node_att_name -\u003e the att name of the nodes to look for\n * @param node_att_val -\u003e the att value of the nodes to look for\n */\ngetNodes: function (xml, node_tag, node_att_name = null, node_att_val = null) {\n\n    let selector = node_tag;\n\n    if (node_att_name !== null) {\n        if (node_att_val !== null) {\n            selector = node_tag + \"[@\" + node_att_name + \"='\" + node_att_val + \"']\"\n        } else {\n            selector = node_tag + \"[@\" + node_att_name + \"]\"\n        }\n    }\n    return xml.findall(\".//\" + selector)\n},\n\n/**\n * Will return the root element of the xml\n */\ngetRoot: function(xml) {\n    return xml.getroot()\n},\n\n/**\n * Will set the text (inner html) in a given node\n */\nsetNodeText: function (node, text) {\n    node.text = text\n},\n\n/**\n * Will return the text (inner html) from a given node\n */\ngetNodeText: function (node) {\n    return node.text\n},\n\n/**\n * Will set attributes to an element\n *\n * @param node -\u003e the node to which the attributes will be appended\n * @param attDict -\u003e the dictionary of attributes to add\n */\nsetNodeAtt: function (node, attDict) {\n    for (let key in attDict) {\n        if (attDict.hasOwnProperty(key)) {\n            node.attrib[key] = attDict[key];\n        }\n    }\n    return node\n},\n\n/**\n * Will remove node attribute\n */\nremoveNodeAtt: function (node, attArr) {\n    for (let i = 0; i \u003c attArr.length; i++) {\n        delete node.attrib[attArr[i]]\n    }\n},\n\n/**\n * Will return the node's attribute value\n */\ngetNodeAttributeValue: function (node, att) {\n    return node.attrib[att]\n},\n\n/**\n * Will return the tag of a given node\n */\ngetNodeTag: function (node) {\n    return node.tag\n},\n```\nAnd more...\n\n\n## Links -\u003e see more tools\n* [os-tools-npm](https://github.com/osfunapps/os-tools-npm) -\u003e This module contains fundamental functions to implement in an npm project\n* [os-file-handler-npm](https://github.com/osfunapps/os-file-handler-npm) -\u003e This module contains fundamental files manipulation functions to implement in an npm project\n* [os-file-stream-handler-npm](https://github.com/osfunapps/os-file-stream-handler-npm) -\u003e This module contains read/write and more advanced operations on files\n* [os-xml-handler-npm](https://github.com/osfunapps/os-xml-handler-npm) -\u003e This module will build, read and manipulate an xml file. Other handy stuff is also available, like search for specific nodes\n\n[GitHub - osfunappsapps](https://github.com/osfunapps)\n\n## Licence\nISC","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosfunapps%2Fos-xml-handler-npm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosfunapps%2Fos-xml-handler-npm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosfunapps%2Fos-xml-handler-npm/lists"}