Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. # XMLDOM [![Build Status](https://secure.travis-ci.org/bigeasy/xmldom.png?branch=master)](http://travis-ci.org/bigeasy/xmldom) [![Coverage Status](https://coveralls.io/repos/bigeasy/xmldom/badge.png?branch=master)](https://coveralls.io/r/bigeasy/xmldom) [![NPM version](https://badge.fury.io/js/xmldom.png)](http://badge.fury.io/js/xmldom)
  2. A JavaScript implementation of W3C DOM for Node.js, Rhino and the browser. Fully
  3. compatible with `W3C DOM level2`; and some compatible with `level3`. Supports
  4. `DOMParser` and `XMLSerializer` interface such as in browser.
  5. Install:
  6. -------
  7. >npm install xmldom
  8. Example:
  9. ====
  10. ```javascript
  11. var DOMParser = require('xmldom').DOMParser;
  12. var doc = new DOMParser().parseFromString(
  13. '<xml xmlns="a" xmlns:c="./lite">\n'+
  14. '\t<child>test</child>\n'+
  15. '\t<child></child>\n'+
  16. '\t<child/>\n'+
  17. '</xml>'
  18. ,'text/xml');
  19. doc.documentElement.setAttribute('x','y');
  20. doc.documentElement.setAttributeNS('./lite','c:x','y2');
  21. var nsAttr = doc.documentElement.getAttributeNS('./lite','x')
  22. console.info(nsAttr)
  23. console.info(doc)
  24. ```
  25. API Reference
  26. =====
  27. * [DOMParser](https://developer.mozilla.org/en/DOMParser):
  28. ```javascript
  29. parseFromString(xmlsource,mimeType)
  30. ```
  31. * **options extension** _by xmldom_(not BOM standard!!)
  32. ```javascript
  33. //added the options argument
  34. new DOMParser(options)
  35. //errorHandler is supported
  36. new DOMParser({
  37. /**
  38. * locator is always need for error position info
  39. */
  40. locator:{},
  41. /**
  42. * you can override the errorHandler for xml parser
  43. * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
  44. */
  45. errorHandler:{warning:function(w){console.warn(w)},error:callback,fatalError:callback}
  46. //only callback model
  47. //errorHandler:function(level,msg){console.log(level,msg)}
  48. })
  49. ```
  50. * [XMLSerializer](https://developer.mozilla.org/en/XMLSerializer)
  51. ```javascript
  52. serializeToString(node)
  53. ```
  54. DOM level2 method and attribute:
  55. ------
  56. * [Node](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247)
  57. attribute:
  58. nodeValue|prefix
  59. readonly attribute:
  60. nodeName|nodeType|parentNode|childNodes|firstChild|lastChild|previousSibling|nextSibling|attributes|ownerDocument|namespaceURI|localName
  61. method:
  62. insertBefore(newChild, refChild)
  63. replaceChild(newChild, oldChild)
  64. removeChild(oldChild)
  65. appendChild(newChild)
  66. hasChildNodes()
  67. cloneNode(deep)
  68. normalize()
  69. isSupported(feature, version)
  70. hasAttributes()
  71. * [DOMImplementation](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-102161490)
  72. method:
  73. hasFeature(feature, version)
  74. createDocumentType(qualifiedName, publicId, systemId)
  75. createDocument(namespaceURI, qualifiedName, doctype)
  76. * [Document](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document) : Node
  77. readonly attribute:
  78. doctype|implementation|documentElement
  79. method:
  80. createElement(tagName)
  81. createDocumentFragment()
  82. createTextNode(data)
  83. createComment(data)
  84. createCDATASection(data)
  85. createProcessingInstruction(target, data)
  86. createAttribute(name)
  87. createEntityReference(name)
  88. getElementsByTagName(tagname)
  89. importNode(importedNode, deep)
  90. createElementNS(namespaceURI, qualifiedName)
  91. createAttributeNS(namespaceURI, qualifiedName)
  92. getElementsByTagNameNS(namespaceURI, localName)
  93. getElementById(elementId)
  94. * [DocumentFragment](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-B63ED1A3) : Node
  95. * [Element](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-745549614) : Node
  96. readonly attribute:
  97. tagName
  98. method:
  99. getAttribute(name)
  100. setAttribute(name, value)
  101. removeAttribute(name)
  102. getAttributeNode(name)
  103. setAttributeNode(newAttr)
  104. removeAttributeNode(oldAttr)
  105. getElementsByTagName(name)
  106. getAttributeNS(namespaceURI, localName)
  107. setAttributeNS(namespaceURI, qualifiedName, value)
  108. removeAttributeNS(namespaceURI, localName)
  109. getAttributeNodeNS(namespaceURI, localName)
  110. setAttributeNodeNS(newAttr)
  111. getElementsByTagNameNS(namespaceURI, localName)
  112. hasAttribute(name)
  113. hasAttributeNS(namespaceURI, localName)
  114. * [Attr](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-637646024) : Node
  115. attribute:
  116. value
  117. readonly attribute:
  118. name|specified|ownerElement
  119. * [NodeList](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177)
  120. readonly attribute:
  121. length
  122. method:
  123. item(index)
  124. * [NamedNodeMap](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1780488922)
  125. readonly attribute:
  126. length
  127. method:
  128. getNamedItem(name)
  129. setNamedItem(arg)
  130. removeNamedItem(name)
  131. item(index)
  132. getNamedItemNS(namespaceURI, localName)
  133. setNamedItemNS(arg)
  134. removeNamedItemNS(namespaceURI, localName)
  135. * [CharacterData](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-FF21A306) : Node
  136. method:
  137. substringData(offset, count)
  138. appendData(arg)
  139. insertData(offset, arg)
  140. deleteData(offset, count)
  141. replaceData(offset, count, arg)
  142. * [Text](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1312295772) : CharacterData
  143. method:
  144. splitText(offset)
  145. * [CDATASection](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-667469212)
  146. * [Comment](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1728279322) : CharacterData
  147. * [DocumentType](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-412266927)
  148. readonly attribute:
  149. name|entities|notations|publicId|systemId|internalSubset
  150. * Notation : Node
  151. readonly attribute:
  152. publicId|systemId
  153. * Entity : Node
  154. readonly attribute:
  155. publicId|systemId|notationName
  156. * EntityReference : Node
  157. * ProcessingInstruction : Node
  158. attribute:
  159. data
  160. readonly attribute:
  161. target
  162. DOM level 3 support:
  163. -----
  164. * [Node](http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent)
  165. attribute:
  166. textContent
  167. method:
  168. isDefaultNamespace(namespaceURI){
  169. lookupNamespaceURI(prefix)
  170. DOM extension by xmldom
  171. ---
  172. * [Node] Source position extension;
  173. attribute:
  174. //Numbered starting from '1'
  175. lineNumber
  176. //Numbered starting from '1'
  177. columnNumber