dom.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.data.dom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.data.dom"] = true;
  8. dojo.provide("dojox.data.dom");
  9. dojo.require("dojox.xml.parser");
  10. //DOM type to int value for reference.
  11. //Ints make for more compact code than full constant names.
  12. //ELEMENT_NODE = 1;
  13. //ATTRIBUTE_NODE = 2;
  14. //TEXT_NODE = 3;
  15. //CDATA_SECTION_NODE = 4;
  16. //ENTITY_REFERENCE_NODE = 5;
  17. //ENTITY_NODE = 6;
  18. //PROCESSING_INSTRUCTION_NODE = 7;
  19. //COMMENT_NODE = 8;
  20. //DOCUMENT_NODE = 9;
  21. //DOCUMENT_TYPE_NODE = 10;
  22. //DOCUMENT_FRAGMENT_NODE = 11;
  23. //NOTATION_NODE = 12;
  24. //This file contains internal/helper APIs as holders for people who used them. They have been migrated to
  25. //a better project, dojox.xml and experimental has been removed there. Please update usage to the new package.
  26. dojo.deprecated("dojox.data.dom", "Use dojox.xml.parser instead.", "2.0");
  27. dojox.data.dom.createDocument = function(/*string?*/ str, /*string?*/ mimetype){
  28. // summary:
  29. // cross-browser implementation of creating an XML document object.
  30. //
  31. // str:
  32. // Optional text to create the document from. If not provided, an empty XML document will be created.
  33. // If str is empty string "", then a new empty document will be created.
  34. // mimetype:
  35. // Optional mimetype of the text. Typically, this is text/xml. Will be defaulted to text/xml if not provided.
  36. dojo.deprecated("dojox.data.dom.createDocument()", "Use dojox.xml.parser.parse() instead.", "2.0");
  37. try{
  38. return dojox.xml.parser.parse(str,mimetype); //DOMDocument.
  39. }catch(e){
  40. /*Squeltch errors like the old parser did.*/
  41. return null;
  42. }
  43. };
  44. dojox.data.dom.textContent = function(/*Node*/node, /*string?*/text){
  45. // summary:
  46. // Implementation of the DOM Level 3 attribute; scan node for text
  47. // description:
  48. // Implementation of the DOM Level 3 attribute; scan node for text
  49. // This function can also update the text of a node by replacing all child
  50. // content of the node.
  51. // node:
  52. // The node to get the text off of or set the text on.
  53. // text:
  54. // Optional argument of the text to apply to the node.
  55. dojo.deprecated("dojox.data.dom.textContent()", "Use dojox.xml.parser.textContent() instead.", "2.0");
  56. if(arguments.length> 1){
  57. return dojox.xml.parser.textContent(node, text); //string
  58. }else{
  59. return dojox.xml.parser.textContent(node); //string
  60. }
  61. };
  62. dojox.data.dom.replaceChildren = function(/*Element*/node, /*Node || array*/ newChildren){
  63. // summary:
  64. // Removes all children of node and appends newChild. All the existing
  65. // children will be destroyed.
  66. // description:
  67. // Removes all children of node and appends newChild. All the existing
  68. // children will be destroyed.
  69. // node:
  70. // The node to modify the children on
  71. // newChildren:
  72. // The children to add to the node. It can either be a single Node or an
  73. // array of Nodes.
  74. dojo.deprecated("dojox.data.dom.replaceChildren()", "Use dojox.xml.parser.replaceChildren() instead.", "2.0");
  75. dojox.xml.parser.replaceChildren(node, newChildren);
  76. };
  77. dojox.data.dom.removeChildren = function(/*Element*/node){
  78. // summary:
  79. // removes all children from node and returns the count of children removed.
  80. // The children nodes are not destroyed. Be sure to call dojo._destroyElement on them
  81. // after they are not used anymore.
  82. // node:
  83. // The node to remove all the children from.
  84. dojo.deprecated("dojox.data.dom.removeChildren()", "Use dojox.xml.parser.removeChildren() instead.", "2.0");
  85. return dojox.xml.parser.removeChildren(node); //int
  86. };
  87. dojox.data.dom.innerXML = function(/*Node*/node){
  88. // summary:
  89. // Implementation of MS's innerXML function.
  90. // node:
  91. // The node from which to generate the XML text representation.
  92. dojo.deprecated("dojox.data.dom.innerXML()", "Use dojox.xml.parser.innerXML() instead.", "2.0");
  93. return dojox.xml.parser.innerXML(node); //string||null
  94. };
  95. }