{"_id":"xml-parse","_rev":"12-4a18b168b574f8f49c7de833d460afab","name":"xml-parse","description":"XML DOM, Parser & Stringifier","dist-tags":{"latest":"0.4.0"},"versions":{"0.1.0":{"name":"xml-parse","version":"0.1.0","description":"XML DOM, Parser & Stringifier","keywords":["xml","xml parser","xml dom","xml stringify","xml parse","xml stringifier","dom","html","html parser","html parsing","xml parsing"],"license":"ISC","author":{"name":"Maurice Conrad"},"main":"main.js","repository":{"type":"git","url":"git://github.com/MauriceConrad/XML-Parser.git"},"git":"git+https://github.com/MauriceConrad/XML-Parser.git","gitHead":"4dd772a9cfb4e496d94b83c9024dc395979e4554","bugs":{"url":"https://github.com/MauriceConrad/XML-Parser/issues"},"homepage":"https://github.com/MauriceConrad/XML-Parser#readme","_id":"xml-parse@0.1.0","scripts":{},"_shasum":"a17d45ebfa27aa9e72612444fd480c7518ce84bf","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"mauriceconrad","email":"conr.maur@googlemail.com"},"dist":{"shasum":"a17d45ebfa27aa9e72612444fd480c7518ce84bf","tarball":"https://registry.npmjs.org/xml-parse/-/xml-parse-0.1.0.tgz","integrity":"sha512-RE+jXZ/icawUTTsQDnjlmAJ81EByEWECfPAkbHAERmlJIJC9p3N5+Y7BDNRyR/gt9RR5+mQnbVJ7Ogx3OGFWMA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCCngAtZlxO64MofzWiu7u5W7vYirAlnzqqSK9N0ujH3AIgU9DY5HluDMLVYcCgq//cY8UgxFlEPeTQr4SqxhOKvaM="}]},"maintainers":[{"name":"mauriceconrad","email":"conr.maur@googlemail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/xml-parse-0.1.0.tgz_1490046422501_0.2613768125884235"},"directories":{}},"0.3.0":{"name":"xml-parse","version":"0.3.0","description":"XML DOM, Parser & Stringifier","keywords":["xml","xml parser","xml dom","xml stringify","xml parse","xml stringifier","dom","html","html parser","html parsing","xml parsing"],"license":"ISC","author":{"name":"Maurice Conrad"},"main":"main.js","repository":{"type":"git","url":"git://github.com/MauriceConrad/XML-Parser.git"},"git":"git+https://github.com/MauriceConrad/XML-Parser.git","gitHead":"029eb5216e2a50db25c4779ca16144575a1aeec6","bugs":{"url":"https://github.com/MauriceConrad/XML-Parser/issues"},"homepage":"https://github.com/MauriceConrad/XML-Parser#readme","_id":"xml-parse@0.3.0","scripts":{},"_shasum":"61b4832d284057ab66a7bcbeabbbae70557ddac1","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"mauriceconrad","email":"conr.maur@googlemail.com"},"dist":{"shasum":"61b4832d284057ab66a7bcbeabbbae70557ddac1","tarball":"https://registry.npmjs.org/xml-parse/-/xml-parse-0.3.0.tgz","integrity":"sha512-zRReP2GvKZffGARV3hRXY66SDUwtdJ+gCOLj2Y2yPc4QU9m0uvAMUrXcABvF0cLz4arQt8eMGWQ+ZomsiUd81A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDl7hNIBvRshfSIRVvCfZSVxLmacVKDwtN2TOGxs54hCQIhAKMoA1NlqIqUCzVHnBMRqBTOgd2on7n0vubah9Cwwcxu"}]},"maintainers":[{"name":"mauriceconrad","email":"conr.maur@googlemail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/xml-parse-0.3.0.tgz_1490263115167_0.0657982612028718"},"directories":{}},"0.3.1":{"name":"xml-parse","version":"0.3.1","description":"XML DOM, Parser & Stringifier","keywords":["xml","xml parser","xml dom","xml stringify","xml parse","xml stringifier","dom","html","html parser","html parsing","xml parsing"],"license":"ISC","author":{"name":"Maurice Conrad"},"main":"main.js","repository":{"type":"git","url":"git://github.com/MauriceConrad/XML-Parser.git"},"git":"git+https://github.com/MauriceConrad/XML-Parser.git","gitHead":"13981098b437c23cf003db30bf5d69510e695f82","bugs":{"url":"https://github.com/MauriceConrad/XML-Parser/issues"},"homepage":"https://github.com/MauriceConrad/XML-Parser#readme","_id":"xml-parse@0.3.1","_npmVersion":"5.4.2","_nodeVersion":"8.2.1","_npmUser":{"name":"mauriceconrad","email":"conr.maur@googlemail.com"},"dist":{"integrity":"sha512-QW0wUpOnyfCLt7QUaRvSCs9GaY2E7eKcl6l5gq4elY/zen4HP69gbWKZGwcmVA5ZG2uYUJf6xMpGOn7e/uG+Dg==","shasum":"0faafdf73350e6ccf00ee8bc18fccf999e641985","tarball":"https://registry.npmjs.org/xml-parse/-/xml-parse-0.3.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDtDx6RZxx/LhiR/WehKKZ7K0wE4WkYCRSHtIZ6Fl506QIgUlgy3fbMQpXvIwwfoi2MC5YywdeIcKG4IxipF7RcT80="}]},"maintainers":[{"name":"mauriceconrad","email":"conr.maur@googlemail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/xml-parse-0.3.1.tgz_1506760942464_0.6553398035466671"},"directories":{}},"0.4.0":{"name":"xml-parse","version":"0.4.0","description":"XML DOM, Parser & Stringifier","keywords":["xml","xml parser","xml dom","xml stringify","xml parse","xml stringifier","dom","html","html parser","html parsing","xml parsing"],"license":"ISC","author":{"name":"Maurice Conrad"},"main":"main.js","repository":{"type":"git","url":"git://github.com/MauriceConrad/XML-Parser.git"},"git":"git+https://github.com/MauriceConrad/XML-Parser.git","gitHead":"2c17e6dc7b43adb567afe175ea0710e5e77b60ef","bugs":{"url":"https://github.com/MauriceConrad/XML-Parser/issues"},"homepage":"https://github.com/MauriceConrad/XML-Parser#readme","_id":"xml-parse@0.4.0","_nodeVersion":"11.12.0","_npmVersion":"6.7.0","dist":{"integrity":"sha512-+wgw8F9dPiBEOD91RnzJ+s9HJcW5jNR8fgtmqqTpa2YEC22TnExMJPnE5tzEbfyPyjeVZqLdLPj6M0k6oqPM0g==","shasum":"9563d935c8df7a9ff90d2443c7eb6f41f368b358","tarball":"https://registry.npmjs.org/xml-parse/-/xml-parse-0.4.0.tgz","fileCount":12,"unpackedSize":21792,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdwzvbCRA9TVsSAnZWagAA148QAI/A8IfGvPv6piOpO3bW\n/13oXKPil1nIIjiQNJ6LvBDqbr4wQTSBa0uP8FNBfUuTh8C91kot90V0LBVy\n6w3znW496lwghfa8eWdI+3rBH2Th/GUnZ7tmqYuylKzVtt6TK2oSL/hLWJa7\nBFlrwUPa5qTNMWisDtiUI51glUOD0PH0MUxNa3idTeYz0moSihqoIpZj3Q7Z\nlYd9Nh3PnVYI6mTvPNmgLjkTIUf0KniPD2trBJb6ICbhMWF7zS1SLHVh8rne\nd1ib/ApAtUIO7sGlCEWRuhcg7DcY/g40aiI35Irz5D0ZCOKxZ7XfC8TGJ5XI\nZzSjBrIOzHCINGEE2gP1IyLQ3qwDqgHNVUU/UnysGQOTxw8P4AjAGWc/Fdye\nE01eoOWIVJnWQIITCL78vC7SFgTzfUsgAWy6oI10eQN3BPqZSpDcsl3TCgjB\n0ONkOgmrQaN9OliK0aAJyAAdNXyDnDOjK/0mFB+NiY98MfEQ+mZKkio0KzpF\njBORYpQWDDZC74mEoo+dfs9txlUpY213rCpqYUAOlfn6eNJHmrVRXgYcb1G1\nV00k8hQ4pSadzrrbAmHkKVYR5v2Z3JqO4TB2N5W0JPt44jJX7gcr5eu4usgv\nnGZte7uXu0UXfZ9U8TDW1HNPk9axhKTLdKqHieyn6xfmYL0iVxcr8DMpXOXa\np9nX\r\n=I73N\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDNiRpsAiVe3AbK6TmWrNUuW/dHCvxiASRy8rl9+DuWbgIge3U/tAF5oAxdBXFZYLq+B5sAr+Q9cocUgaQsC+LBU1c="}]},"maintainers":[{"name":"mauriceconrad","email":"conr.maur@googlemail.com"}],"_npmUser":{"name":"mauriceconrad","email":"conr.maur@googlemail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/xml-parse_0.4.0_1573075930974_0.2973904159582448"},"_hasShrinkwrap":false}},"readme":"# XML Parser, Stringifier and DOM\n\nParse XML, HTML and more with a very tolerant XML parser and convert it into a DOM.\n\nThese three components are separated from each other as own modules.\n\n|Component|Size|\n|---|---|\n|Parser|4.7 KB|\n|Stringifier|1.3 KB|\n|DOM|3.1 KB|\n\n## Install\n```bash\nnpm install xml-parse\n```\n## Require\n```javascript\nconst xml = require(\"xml-parse\");\n```\n\n## Parser\n\nParsing is very simple.\n\nJust call the ```parse``` method of the *xml-parse* instance.\n\n```javascript\nconst xml = require(\"xml-parse\");\n\n// Valid XML string\nvar parsedXML = xml.parse('<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n                          '<root>Root Element</root>');\nconsole.log(parsedXML);\n\n// Invalid XML string\nvar parsedInavlidXML = xml.parse('<root></root>' +\n                                 '<secondRoot>' +\n                                   '<notClosedTag>' +\n                                 '</secondRoot>');\nconsole.log(parsedInavlidXML);\n```\n\n### Parsed Object Structure\n\nThe result of ```parse``` is an object that maybe looks like this:\n\n(In this case we have the xml string of the given example)\n```javascript\n[\n  {\n    type: 'element',\n    tagName: '?xml',\n    attributes: {\n      version: '1.0',\n      encoding: 'UTF-8'\n    },\n    childNodes: [],\n    innerXML: '>',\n    closing: false,\n    closingChar: '?'\n  },\n  {\n    type: 'element',\n    tagName: 'root',\n    attributes: {},\n    childNodes: [\n      {\n        type: 'text',\n        text: 'Root Element'\n      }\n    ],\n    innerXML: 'Root Element',\n    closing: true,\n    closingChar: null\n  }\n]\n```\n**The root object is always an array because of the fact that it handles invalid xml with more than one root element.**\n\n#### Object Nodes\n\nThere are two kinds of objects. *element* and *text*.\nAn object has always the property ```type```.\nThe other keys depend from this *type*.\n\n##### 'Element' Object Node\n\n```javascript\n{\n  type: [String], // \"element\"\n  tagName: [String], // The tag name of the tag\n  attributes: [Object], // Object containing attributes as properties\n  childNodes: [Array], // Array containing child nodes as object nodes (\"element\" or \"text\")\n  innerXML: [String], // The inner XML of the tag\n  closing: [Boolean], // If the tag is closed typically (</tagName>)\n  closingChar: [String] || null // If it is not closed typically, the char that is used to close it (\"!\" or \"?\")\n}\n```\n\n##### 'Text' Object Node\n```javascript\n{\n  type: [String], // \"text\"\n  text: [String] // Text contents of the text node\n}\n```\n\n## Stringifier\n\nThe stringifier is the simplest component. Just pass a parsed object structure.\n\n```javascript\nconst xml = require(\"xml-parse\");\n\nvar xmlDoc = [\n  {\n    type: 'element',\n    tagName: '?xml',\n    attributes: {\n      version: '1.0',\n      encoding: 'UTF-8'\n    },\n    childNodes: [],\n    innerXML: '>',\n    closing: false,\n    closingChar: '?'\n  },\n  {\n    type: 'element',\n    tagName: 'root',\n    attributes: {},\n    childNodes: [\n      {\n        type: 'text',\n        text: 'Root Element'\n      }\n    ],\n    innerXML: 'Root Element',\n    closing: true,\n    closingChar: null\n  }\n]\n\nvar xmlStr = xml.stringify(xmlDoc, 2); // 2 spaces\n\nconsole.log(xmlStr);\n```\n\n\n## DOM\n\nThe ```DOM``` method of *xml-parser* instance returns a Document-Object-Model with a few methods.\nIt is oriented on the official W3 DOM but not complex as the original.\n\n```javascript\nconst xml = require(\"xml-parse\");\n\nvar xmlDoc = new xml.DOM(xml.parse('<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n                                     '<root>Root Element</root>')); // Can also be a file path.\n\nxmlDoc.document; // Document Object. (Root)\n```\n\n### 'Element' Object Node\n\n```javascript\n// An element (e.g the 'document' object) has the following prototype methods and properties:\n\nvar objectNode = document.childNodes[1]; // Just an example\n\n// This is the return of a object node element\n\nobjectNode = {\n  type: 'element',\n  tagName: 'tagName',\n  attributes: [Object],\n  childNodes: [Object],\n  innerXML: 'innerXML',\n  closing: true,\n  closingChar: null,\n  getElementsByTagName: [Function], // Returns all child nodes with a specific tagName\n  getElementsByAttribute: [Function], // Returns all child nodes with a specific attribute value\n  removeChild: [Function], // Removes a child node\n  appendChild: [Function], // Appends a child node\n  insertBefore: [Function], // Inserts a child node\n  getElementsByCheckFunction: [Function], // Returns all child nodes that are validated by validation function\n  parentNode: [Circular] // Parent Node\n}\n```\n\n### Handling with child nodes\n\nWith ```appendChild``` or ```insertBefore``` methods of every object node, you are allowed to append a child node. You do not have to do something like ```createElement```.\n\nBecause a child node is just an object literal, with some properties like ```type```, ```tagName```, ```attributes```and more you just have to pass such an object to the function.\n\n#### appendChild\n\n```javascript\nelement.appendChild(childNode); // ChildNode is just a object node\n```\n\n##### Example\n\n```javascript\nconst xml = require('xml-parse');\n\nvar xmlDoc = new xml.DOM(xml.parse('<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n                                     '<root>Root Element</root>'));\n\nvar root = xmlDoc.document.getElementsByTagName(\"root\")[0];\n\nroot.appendChild({\n  type: \"element\",\n  tagName: \"appendedElement\",\n  childNodes: [\n    {\n      type: \"text\",\n      text: \"Hello World :) I'm appended!\"\n    }\n  ]\n});\n```\n\n#### insertBefore\n\n```javascript\nelement.insertBefore(childNode, elementAfter); // ChildNode is just an object literal, 'elementAfter' is just a child node of the parent element\n```\n\n##### Example\n\n```javascript\nconst xml = require('xml-parse');\n\nvar xmlDoc = new xml.DOM(xml.parse('<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n                                     '<root>Root Element</root>'));\n\nvar root = xmlDoc.document.getElementsByTagName(\"root\")[0];\n\nroot.insertBefore({\n  type: \"element\",\n  tagName: \"insertedElement\",\n  childNodes: [\n    {\n      type: \"text\",\n      text: \"Hello World :) I'm appended!\"\n    }\n  ]\n}, root.childNodes[0]);\n```\n\n#### removeChild\n\n```javascript\nelement.removeChild(childNode); // 'childNode' is just a children of the parent element ('element')\n```\n\n##### Example\n\n```javascript\nconst xml = require('xml-parse');\n\nvar xmlDoc = new xml.DOM(xml.parse('<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n                                     '<root>Root Element</root>'));\n\nvar root = xmlDoc.document.getElementsByTagName(\"root\")[0];\n\nroot.removeChild(root.childNodes[0]);\n\n```\n\n### parentNode\n\nThe ```parentNode``` of a object node represents its parent element. It's a ```[Circular]``` reference.\n\n```javascript\nconst xml = require('xml-parse');\n\nvar xmlDoc = new xml.DOM(xml.parse('<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n                                     '<root>Root Element</root>'));\n\nvar root = xmlDoc.document.getElementsByTagName(\"root\")[0];\n\nconsole.log(root.childNodes[0].parentNode); // Returns the 'root' element\n```\n\n## Get child nodes\n\n### getElementsByTagName\n\n```javascript\nelement.getElementsByTagName(\"myTagName\"); // Returns all elements whose tag name is 'myTagName'\n```\n\n### getElementsByAttribute\n\n```javascript\nelement.getElementsByAttribute(\"myAttribute\", \"myAttributeValue\"); // Returns all elements whose attribute 'myAttribute' is 'myAttributeValue'\n```\n\n### getElementsByCheckFunction\n\n```javascript\n// With this method you can set custom 'get' methods.\nelement.getElementsByCheckFunction(function(element) {\n  if (element.type === \"element\" && element.childNodes.length == 30) {\n    return true;\n  }\n}); // Returns all elements that have exactly 30 childNodes\n```\n","maintainers":[{"name":"mauriceconrad","email":"conr.maur@googlemail.com"}],"time":{"modified":"2022-06-29T05:36:46.012Z","created":"2017-03-20T21:47:03.170Z","0.1.0":"2017-03-20T21:47:03.170Z","0.1.1":"2017-03-22T15:52:39.420Z","0.1.2":"2017-03-22T16:30:39.658Z","0.2.0":"2017-03-23T09:54:40.708Z","0.3.0":"2017-03-23T09:58:37.111Z","0.3.1":"2017-09-30T08:42:23.515Z","0.4.0":"2019-11-06T21:32:11.128Z"},"homepage":"https://github.com/MauriceConrad/XML-Parser#readme","keywords":["xml","xml parser","xml dom","xml stringify","xml parse","xml stringifier","dom","html","html parser","html parsing","xml parsing"],"repository":{"type":"git","url":"git://github.com/MauriceConrad/XML-Parser.git"},"author":{"name":"Maurice Conrad"},"bugs":{"url":"https://github.com/MauriceConrad/XML-Parser/issues"},"license":"ISC","readmeFilename":"README.md"}