{"id":25611070,"url":"https://github.com/g6ling/react-native-html-parser","last_synced_at":"2025-02-21T23:01:16.586Z","repository":{"id":57337471,"uuid":"56859839","full_name":"choru-k/react-native-html-parser","owner":"choru-k","description":"can use html parser in react-native/titanium and anywhere","archived":false,"fork":false,"pushed_at":"2020-02-04T03:35:27.000Z","size":66,"stargazers_count":83,"open_issues_count":9,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-15T18:02:57.819Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/choru-k.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":"2016-04-22T14:07:05.000Z","updated_at":"2025-02-11T15:48:37.000Z","dependencies_parsed_at":"2022-09-13T02:41:52.295Z","dependency_job_id":null,"html_url":"https://github.com/choru-k/react-native-html-parser","commit_stats":null,"previous_names":["choru-k/react-native-html-parser","g6ling/react-native-html-parser"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choru-k%2Freact-native-html-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choru-k%2Freact-native-html-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choru-k%2Freact-native-html-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choru-k%2Freact-native-html-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/choru-k","download_url":"https://codeload.github.com/choru-k/react-native-html-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100531,"owners_count":19747688,"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":"2025-02-21T23:01:05.575Z","updated_at":"2025-02-21T23:01:16.523Z","avatar_url":"https://github.com/choru-k.png","language":"JavaScript","readme":"# react-native-html-parser\n\ncan use html parser in react-native, titanium, and anywhere. This is based on [xmldom](https://github.com/jindw/xmldom).\n\nInstall:\n-------\n\u003enpm install react-native-html-parser\n\nExample:\n====\n```javascript\nimport React, {\n    Component,\n    View,\n    Text,\n    StyleSheet,\n    TextInput,\n    WebView,\n} from 'react-native'\n\n\nvar DomParser = require('react-native-html-parser').DOMParser\nclass TestReactNativeHtmlParser extends Component {\n    componentDidMount() {\n        let html = `\u003chtml\u003e\n                        \u003cbody\u003e\n                            \u003cdiv id=\"b a\"\u003e\n                                \u003ca href=\"example.org\"\u003e\n                                \u003cdiv class=\"inA\"\u003e\n                                    \u003cbr\u003ebbbb\u003c/br\u003e\n                                \u003c/div\u003e\n                            \u003c/div\u003e\n                            \u003cdiv class=\"bb a\"\u003e\n                                Test\n                            \u003c/div\u003e\n                        \u003c/body\u003e\n                    \u003c/html\u003e`\n        let doc = new DomParser().parseFromString(html,'text/html')\n        \n        console.log(doc.querySelect('#b .inA'))\n        console.log(doc.getElementsByTagName('a'))\n\t\t\t\tconsole.log(doc.querySelect('#b a[href=\"example.org\"]'))\n\t\t\t\tconsole.log(doc.getElementsByClassName('a', false))\n    }\n    \n}\n```\nor\n```javascript\nvar DOMParser = require('react-native-html-parser').DOMParser;\nvar doc = new DOMParser().parseFromString(\n    '\u003chtml\u003e\u003cbody\u003e'+\n    '\u003cdiv id=\"a\" class=\"a\"\u003e'+\n        '\u003ca class=\"b\"\u003eabcd\u003c/a\u003e'+\n    '\u003c/div\u003e'+\n    '\u003cdiv class=\"b\"\u003e'+\n        '\u003ca href=\"aa\" id=\"b\"\u003e'+\n    '\u003c/div\u003e'+\n    '\u003c/body\u003e\u003c/html\u003e'\n    ,'text/html');\n\nconsole.log(doc.getElementsByAttribute('class', 'b'));\nconsole.log(querySelecotr('.div.aa       class#a a'))\nconsole.log(getElementsBySelector('div.aa#in[ii=\"a\"]'))\nconsole.log(doc.querySelect('div.a a.b'))\nconsole.log('end')\n```\nor\n```javascript\nimport DOMParser from 'react-native-html-parser';\n\nconst html = `\u003cp\u003eHello world \u003cb\u003eworld\u003c/b\u003e \u003ci\u003efoo\u003c/i\u003e abc\u003c/p\u003e`;    \nconst parser = new DOMParser.DOMParser();\nconst parsed = parser.parseFromString(html, 'text/html');\n\n...\n```\n\n# error solution\n#### [xmldom error] entity not found: ~~~~~\nCheck this [issue](https://github.com/g6ling/react-native-html-parser/issues/4)\n\nAPI Reference\n=====\n\n * [DOMParser](https://developer.mozilla.org/en/DOMParser):\n\n\t```javascript\n\tparseFromString(xmlsource,mimeType)\n\t```\n\t* **options extension** _by xmldom_(not BOM standard!!)\n\n\t```javascript\n\t//added the options argument\n\tnew DOMParser(options)\n\t\n\t//errorHandler is supported\n\tnew DOMParser({\n\t\t/**\n\t\t * locator is always need for error position info\n\t\t */\n\t\tlocator:{},\n\t\t/**\n\t\t * you can override the errorHandler for xml parser\n\t\t * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html\n\t\t */\n\t\terrorHandler:{warning:function(w){console.warn(w)},error:callback,fatalError:callback}\n\t\t//only callback model\n\t\t//errorHandler:function(level,msg){console.log(level,msg)}\n\t})\n\t\t\n\t```\n\n * [XMLSerializer](https://developer.mozilla.org/en/XMLSerializer)\n \n\t```javascript\n\tserializeToString(node)\n\t```\nDOM level2 method and attribute:\n------\n\n * [Node](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247)\n\t\n\t\tattribute:\n\t\t\tnodeValue|prefix\n\t\treadonly attribute:\n\t\t\tnodeName|nodeType|parentNode|childNodes|firstChild|lastChild|previousSibling|nextSibling|attributes|ownerDocument|namespaceURI|localName\n\t\tmethod:\t\n\t\t\tinsertBefore(newChild, refChild)\n\t\t\treplaceChild(newChild, oldChild)\n\t\t\tremoveChild(oldChild)\n\t\t\tappendChild(newChild)\n\t\t\thasChildNodes()\n\t\t\tcloneNode(deep)\n\t\t\tnormalize()\n\t\t\tisSupported(feature, version)\n\t\t\thasAttributes()\n\n * [DOMImplementation](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-102161490)\n\t\t\n\t\tmethod:\n\t\t\thasFeature(feature, version)\n\t\t\tcreateDocumentType(qualifiedName, publicId, systemId)\n\t\t\tcreateDocument(namespaceURI, qualifiedName, doctype)\n\n * [Document](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document) : Node\n\t\t\n\t\treadonly attribute:\n\t\t\tdoctype|implementation|documentElement\n\t\tmethod:\n\t\t\tcreateElement(tagName)\n\t\t\tcreateDocumentFragment()\n\t\t\tcreateTextNode(data)\n\t\t\tcreateComment(data)\n\t\t\tcreateCDATASection(data)\n\t\t\tcreateProcessingInstruction(target, data)\n\t\t\tcreateAttribute(name)\n\t\t\tcreateEntityReference(name)\n\t\t\tgetElementsByTagName(tagname)\n\t\t\timportNode(importedNode, deep)\n\t\t\tcreateElementNS(namespaceURI, qualifiedName)\n\t\t\tcreateAttributeNS(namespaceURI, qualifiedName)\n\t\t\tgetElementsByTagNameNS(namespaceURI, localName)\n\t\t\tgetElementById(elementId)\n            getElementByClassName(classname)\n            querySelect(query) // querySelect only support tagName,className,Attribute,id, parent descendant\n\n * [DocumentFragment](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-B63ED1A3) : Node\n * [Element](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-745549614) : Node\n\t\t\n\t\treadonly attribute:\n\t\t\ttagName\n\t\tmethod:\n\t\t\tgetAttribute(name)\n\t\t\tsetAttribute(name, value)\n\t\t\tremoveAttribute(name)\n\t\t\tgetAttributeNode(name)\n\t\t\tsetAttributeNode(newAttr)\n\t\t\tremoveAttributeNode(oldAttr)\n\t\t\tgetElementsByTagName(name)\n\t\t\tgetAttributeNS(namespaceURI, localName)\n\t\t\tsetAttributeNS(namespaceURI, qualifiedName, value)\n\t\t\tremoveAttributeNS(namespaceURI, localName)\n\t\t\tgetAttributeNodeNS(namespaceURI, localName)\n\t\t\tsetAttributeNodeNS(newAttr)\n\t\t\tgetElementsByTagNameNS(namespaceURI, localName)\n\t\t\thasAttribute(name)\n\t\t\thasAttributeNS(namespaceURI, localName)\n            getElementByClassName(classname)\n            querySelect(query) // querySelect only support tagName,className,Attribute,id, parent descendant\n\n * [Attr](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-637646024) : Node\n\t\n\t\tattribute:\n\t\t\tvalue\n\t\treadonly attribute:\n\t\t\tname|specified|ownerElement\n\n * [NodeList](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177)\n\t\t\n\t\treadonly attribute:\n\t\t\tlength\n\t\tmethod:\n\t\t\titem(index)\n\t\n * [NamedNodeMap](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1780488922)\n\n\t\treadonly attribute:\n\t\t\tlength\n\t\tmethod:\n\t\t\tgetNamedItem(name)\n\t\t\tsetNamedItem(arg)\n\t\t\tremoveNamedItem(name)\n\t\t\titem(index)\n\t\t\tgetNamedItemNS(namespaceURI, localName)\n\t\t\tsetNamedItemNS(arg)\n\t\t\tremoveNamedItemNS(namespaceURI, localName)\n\t\t\n * [CharacterData](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-FF21A306) : Node\n\t\n\t\tmethod:\n\t\t\tsubstringData(offset, count)\n\t\t\tappendData(arg)\n\t\t\tinsertData(offset, arg)\n\t\t\tdeleteData(offset, count)\n\t\t\treplaceData(offset, count, arg)\n\t\t\n * [Text](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1312295772) : CharacterData\n\t\n\t\tmethod:\n\t\t\tsplitText(offset)\n\t\t\t\n * [CDATASection](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-667469212)\n * [Comment](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1728279322) : CharacterData\n\t\n * [DocumentType](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-412266927)\n\t\n\t\treadonly attribute:\n\t\t\tname|entities|notations|publicId|systemId|internalSubset\n\t\t\t\n * Notation : Node\n\t\n\t\treadonly attribute:\n\t\t\tpublicId|systemId\n\t\t\t\n * Entity : Node\n\t\n\t\treadonly attribute:\n\t\t\tpublicId|systemId|notationName\n\t\t\t\n * EntityReference : Node \n * ProcessingInstruction : Node \n\t\n\t\tattribute:\n\t\t\tdata\n\t\treadonly attribute:\n\t\t\ttarget\n\t\t\nDOM level 3 support:\n-----\n\n * [Node](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent)\n\t\t\n\t\tattribute:\n\t\t\ttextContent\n\t\tmethod:\n\t\t\tisDefaultNamespace(namespaceURI){\n\t\t\tlookupNamespaceURI(prefix)\n\nDOM extension by xmldom\n---\n * [Node] Source position extension; \n\t\t\n\t\tattribute:\n\t\t\t//Numbered starting from '1'\n\t\t\tlineNumber\n\t\t\t//Numbered starting from '1'\n\t\t\tcolumnNumber\n","funding_links":[],"categories":["Components"],"sub_categories":["Utils \u0026 Infra"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg6ling%2Freact-native-html-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg6ling%2Freact-native-html-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg6ling%2Freact-native-html-parser/lists"}