{"id":15450593,"url":"https://github.com/zhengsk/xmlparsing","last_synced_at":"2025-06-22T17:08:57.568Z","repository":{"id":57401928,"uuid":"145117720","full_name":"zhengsk/xmlparsing","owner":"zhengsk","description":"An xml parser.","archived":false,"fork":false,"pushed_at":"2020-02-02T15:20:07.000Z","size":670,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-20T02:22:58.216Z","etag":null,"topics":["ast","generator","parser","xml"],"latest_commit_sha":null,"homepage":"https://zhengsk.github.io/xmlparsing/","language":"TypeScript","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/zhengsk.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}},"created_at":"2018-08-17T12:26:39.000Z","updated_at":"2021-07-29T10:09:56.000Z","dependencies_parsed_at":"2022-09-15T18:41:46.876Z","dependency_job_id":null,"html_url":"https://github.com/zhengsk/xmlparsing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zhengsk/xmlparsing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengsk%2Fxmlparsing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengsk%2Fxmlparsing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengsk%2Fxmlparsing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengsk%2Fxmlparsing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhengsk","download_url":"https://codeload.github.com/zhengsk/xmlparsing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengsk%2Fxmlparsing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261217734,"owners_count":23126266,"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":["ast","generator","parser","xml"],"created_at":"2024-10-01T21:06:39.874Z","updated_at":"2025-06-22T17:08:52.549Z","avatar_url":"https://github.com/zhengsk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xmlparsing\n\n\u003e XML 解析器，支持布尔属性、自结束标签元素、保持元素属性。\n\n## 安装\n\n```shell\nnpm i xmlparsing\n```\n\n## 使用\n\n```js\nimport { parser, generator } from 'xmlparsing';\n\n// parse\nconst xmlDocument = parser.parse('\u003chello class=\"red\"\u003e\u003c/hello\u003e');\n\n// firstChild\nconst helloElement = xmlDocument.firstChild;\n\n// tagName\nconsole.info(helloElement.tagName); // hello\n\n// getAttribute\nconsole.info(helloElement.getAttribute('class')); // red;\n\nhelloElement.setAttribute('class', 'green');\n\n// generate\ngenerator.generate(xmlDocument); // \u003chello class=\"green\"\u003e\u003c/hello\u003e\n```\n\n## 元素类型\n\n- Document\n- Element\n- Fragment\n- Text\n- Comment\n- Cdata\n\n## 属性\n\n### nodeType\n\n类型：string\n\n节点类型：document、element、fragment、text、comment、cdata 类型\n\n### nodeValue\n\n类型：string | null\n\n节点值：Text 节点、Comment 节点、Cdata 节点的文本内容，其他节点的 nodeValue 为 null\n\n### children [Node]\n\n所有子节点数组\n\n### parentNode\n\n父节点\n\n### previousSibling\n\n前一个兄弟节点\n\n### previousElementSibling\n\n前一个兄弟元素节点\n\n### nextSibling\n\n后一个兄弟节点\n\n### nextElementSibling\n\n后一个兄弟元素节点\n\n### firstChild\n\n第一个子节点\n\n### lastChild\n\n最后一个子节点\n\n### outerXML\n\n节点字符串文本\n\n### innerXML\n\n所有子节点的字符串文本\n\n## 方法\n\n### getAttribute(attributName)\n\n说明：获取属性值\n\n参数：attributeName 属性名\n\n```js\n// \u003cdiv class=\"hello\" /\u003e\nnode.getAttribute('class'); // 'hello'\n```\n\n### setAttribute(attributeName, newValue)\n\n说明： 设置属性值\n\n参数： attributeName 属性名， newValue 属性值\n\n```js\n// \u003cdiv class=\"hello\" /\u003e\nnode.getAttribute('class', 'green');\nnode.getAttribute('id', 'abc'); // \u003cdiv class=\"green\" id=\"abc\"\u003e\u003c/div\u003e\n```\n\n### removeAttribute(attributeName)\n\n说明： 删除节点属性\n\n参数： attributeName\n\n```js\n// \u003cdiv class=\"hello\" /\u003e\nnode.removeAttribute('class');\nnode.getAttribute('id', 'abc'); // \u003cdiv\u003e\u003c/div\u003e\n```\n\n### hasAttribute(attributName)\n\n说明： 判断节点是否有纯在的属性\n\n参数： attributeName\n\n```js\n// \u003cdiv class=\"hello\" /\u003e\nnode.removeAttribute('class');\nnode.getAttribute('id', 'abc'); // \u003cdiv\u003e\u003c/div\u003e\n```\n\n### appendChild(childNode)\n\n说明： 添加子节点\n\n参数： childNode\n\n```js\n// \u003cdiv class=\"hello\" /\u003e\nconst newNode = node.createElement('xyz');\nnode.appendChild(newNode); // \u003cdiv class=\"hello\"\u003e\u003cxyz\u003e\u003c/xyz\u003e\u003c/div\u003e\n```\n\n### insertBefore(newNode, referenceNode)\n\n说明： 在参考节点前插入节点\n\n参数： newNode 新节点，referenceNode 参考相关节点\n\n```js\n// \u003cdiv\u003e\u003cx /\u003e\u003c/div\u003e\nconst newNode = node.createElement('y');\nnode.insertBefore(newNode, node.firstChild); // \u003cdiv\u003e\u003cy\u003e\u003c/y\u003e\u003cx /\u003e\u003c/div\u003e\n```\n\n### insertAfter(newNode, referenceNode)\n\n说明： 在参考节点后插入节点\n\n参数： newNode 新节点，referenceNode 参考相关节点\n\n```js\n// \u003cdiv\u003e\u003cx /\u003e\u003c/div\u003e\nconst newNode = node.createElement('y');\nnode.insertAfter(newNode, node.firstChild); // \u003cdiv\u003e\u003cx /\u003e\u003cy\u003e\u003c/y\u003e\u003c/div\u003e\n```\n\n### before(newNode[, newNode...])\n\n说明：在节点前添加新节点\n\n参数： newNode\n\n```js\n// \u003cdiv\u003e\u003c/div\u003e\nconst newNode = node.createElement('y');\nnode.before(newNode); // \u003cy\u003e\u003c/y\u003e\u003cdiv\u003e\u003c/div\u003e\n```\n\n### after(newNode[, newNode...])\n\n说明：在节点后添加新节点\n\n参数： newNode\n\n```js\n// \u003cdiv\u003e\u003c/div\u003e\nconst newNode = node.createElement('y');\nnode.after(newNode); // \u003cdiv\u003e\u003c/div\u003e\u003cy\u003e\u003c/y\u003e\n```\n\n### removeChild(childNode)\n\n说明：删除子节点\n\n参数： newNode\n\n```js\n// \u003cdiv\u003e\u003ca /\u003e\u003cb /\u003e\u003c/div\u003e\nconst newNode = node.removeChild(node.firstChild); \u003cdiv\u003e\u003cb /\u003e\u003c/div\u003e\n```\n\n\n### replaceWith(newNode)\n\n说明：用新节点替换节点本身\n\n### remove()\n\n说明：删除节点本身\n\n### empty()\n\n说明：清空节点所有子节点\n\n### cloneNode([deep])\n\n说明：克隆节点本身\n\n### toString()\n\n说明：返回节点字符串序列\n\n### getElementsByTagName(tagName)\n\n说明：返回所有指定节点名称的所有子节点\n\n### createElement(nodeType)\n\n说明：创建新元素节点\n\n### createComment([commentText])\n\n说明：创建注释节点\n\n### createTextNode([text])\n\n说明：创建文本节点\n\n### createFragment()\n\n说明：创建片段节点\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengsk%2Fxmlparsing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhengsk%2Fxmlparsing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengsk%2Fxmlparsing/lists"}